Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fc5653d

Browse files
committed
Add stdout and stderr as optional parameters
1 parent b1f872a commit fc5653d

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

‎corenlp/client.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import shlex
99
import subprocess
1010
import time
11+
import sys
1112

1213
from six.moves.urllib.parse import urlparse
1314

@@ -48,10 +49,13 @@ class RobustService(object):
4849
"""
4950
TIMEOUT = 15
5051

51-
def __init__(self, start_cmd, stop_cmd, endpoint):
52+
def __init__(self, start_cmd, stop_cmd, endpoint, stdout=sys.stdout,
53+
stderr=sys.stderr):
5254
self.start_cmd = start_cmd and shlex.split(start_cmd)
5355
self.stop_cmd = stop_cmd and shlex.split(stop_cmd)
5456
self.endpoint = endpoint
57+
self.stdout = stdout
58+
self.stderr = stderr
5559

5660
self.server = None
5761
self.is_active = False
@@ -64,7 +68,9 @@ def is_alive(self):
6468

6569
def start(self):
6670
if self.start_cmd:
67-
self.server = subprocess.Popen(self.start_cmd)
71+
self.server = subprocess.Popen(self.start_cmd,
72+
stderr=self.stderr,
73+
stdout=self.stdout)
6874

6975
def stop(self):
7076
if self.server:
@@ -116,7 +122,10 @@ class CoreNLPClient(RobustService):
116122
DEFAULT_ANNOTATORS = "tokenize ssplit lemma pos ner depparse".split()
117123
DEFAULT_PROPERTIES = {}
118124

119-
def __init__(self, start_server=True, endpoint="http://localhost:9000", timeout=5000, annotators=DEFAULT_ANNOTATORS, properties=DEFAULT_PROPERTIES):
125+
def __init__(self, start_server=True, endpoint="http://localhost:9000",
126+
timeout=5000, annotators=DEFAULT_ANNOTATORS,
127+
properties=DEFAULT_PROPERTIES, stdout=sys.stdout,
128+
stderr=sys.stderr):
120129
if start_server:
121130
host, port = urlparse(endpoint).netloc.split(":")
122131
assert host == "localhost", "If starting a server, endpoint must be localhost"
@@ -130,7 +139,8 @@ def __init__(self, start_server=True, endpoint="http://localhost:9000", timeout=
130139
else:
131140
start_cmd = stop_cmd = None
132141

133-
super(CoreNLPClient, self).__init__(start_cmd, stop_cmd, endpoint)
142+
super(CoreNLPClient, self).__init__(start_cmd, stop_cmd, endpoint,
143+
stdout, stderr)
134144
self.default_annotators = annotators
135145
self.default_properties = properties
136146

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /