diff --git a/pyknp/juman/juman.py b/pyknp/juman/juman.py index 26f5a56..7022e1b 100644 --- a/pyknp/juman/juman.py +++ b/pyknp/juman/juman.py @@ -52,12 +52,13 @@ def __init__(self, self.ignorepattern = ignorepattern self.pattern = pattern if server is not None: - self.analyzer = Analyzer(backend='socket', server=server, port=port, socket_option='RUN -e2\n') + self.analyzer = Analyzer(backend='socket', timeout=timeout, server=server, port=port, + socket_option='RUN -e2\n') else: cmds = [self.command] + self.options if self.rcfile: cmds += ['-r', self.rcfile] - self.analyzer = Analyzer(backend='subprocess', multithreading=multithreading, command=cmds) + self.analyzer = Analyzer(backend='subprocess', multithreading=multithreading, timeout=timeout, command=cmds) if self.rcfile and not os.path.isfile(os.path.expanduser(self.rcfile)): raise Exception("Can't read rcfile (%s)!" % self.rcfile) diff --git a/pyknp/knp/knp.py b/pyknp/knp/knp.py index 17b596a..7bd7f00 100644 --- a/pyknp/knp/knp.py +++ b/pyknp/knp/knp.py @@ -52,12 +52,13 @@ def __init__(self, self.rcfile = rcfile self.pattern = pattern if server is not None: - self.analyzer = Analyzer(backend='socket', server=server, port=port, socket_option='RUN -tab -normal\n') + self.analyzer = Analyzer(backend='socket', timeout=timeout, server=server, port=port, + socket_option='RUN -tab -normal\n') else: cmds = [self.command] + self.options if self.rcfile: cmds += ['-r', self.rcfile] - self.analyzer = Analyzer(backend='subprocess', multithreading=multithreading, command=cmds) + self.analyzer = Analyzer(backend='subprocess', multithreading=multithreading, timeout=timeout, command=cmds) self.jumanpp = jumanpp if self.rcfile and not os.path.isfile(os.path.expanduser(self.rcfile)): diff --git a/pyknp/utils/analyzer.py b/pyknp/utils/analyzer.py index 58f346d..3becf24 100644 --- a/pyknp/utils/analyzer.py +++ b/pyknp/utils/analyzer.py @@ -12,9 +12,18 @@ class Analyzer(object): command (list): サブプロセスに渡すコマンド """ - def __init__(self, backend, multithreading=False, server=None, port=None, socket_option=None, command=None): + def __init__(self, + backend, + multithreading=False, + server=None, + port=None, + socket_option=None, + command=None, + timeout=180, + ): self.backend = backend self.multithreading = multithreading + self.timeout = timeout self.socket = None self.server = server @@ -30,9 +39,9 @@ def query(self, input_str, pattern): self.socket = Socket(self.server, self.port, self.socket_option) else: if self.multithreading is True: - self.subprocess = SubprocessThreadSafe(self.command) + self.subprocess = SubprocessThreadSafe(self.command, timeout=self.timeout) else: - self.subprocess = Subprocess(self.command) + self.subprocess = Subprocess(self.command, timeout=self.timeout) if self.socket: return self.socket.query(input_str, pattern=pattern)