MCPcopy Create free account
hub / github.com/EasyIME/PIME / Subprocess

Class Subprocess

python/python3/tornado/process.py:187–373  ·  view source on GitHub ↗

Wraps ``subprocess.Popen`` with IOStream support. The constructor is the same as ``subprocess.Popen`` with the following additions: * ``stdin``, ``stdout``, and ``stderr`` may have the value ``tornado.process.Subprocess.STREAM``, which will make the corresponding attribute

Source from the content-addressed store, hash-verified

185
186
187class Subprocess(object):
188 """Wraps ``subprocess.Popen`` with IOStream support.
189
190 The constructor is the same as ``subprocess.Popen`` with the following
191 additions:
192
193 * ``stdin``, ``stdout``, and ``stderr`` may have the value
194 ``tornado.process.Subprocess.STREAM``, which will make the corresponding
195 attribute of the resulting Subprocess a `.PipeIOStream`. If this option
196 is used, the caller is responsible for closing the streams when done
197 with them.
198
199 The ``Subprocess.STREAM`` option and the ``set_exit_callback`` and
200 ``wait_for_exit`` methods do not work on Windows. There is
201 therefore no reason to use this class instead of
202 ``subprocess.Popen`` on that platform.
203
204 .. versionchanged:: 5.0
205 The ``io_loop`` argument (deprecated since version 4.1) has been removed.
206
207 """
208
209 STREAM = object()
210
211 _initialized = False
212 _waiting = {} # type: ignore
213 _old_sigchld = None
214
215 def __init__(self, *args: Any, **kwargs: Any) -> None:
216 self.io_loop = ioloop.IOLoop.current()
217 # All FDs we create should be closed on error; those in to_close
218 # should be closed in the parent process on success.
219 pipe_fds = [] # type: List[int]
220 to_close = [] # type: List[int]
221 if kwargs.get("stdin") is Subprocess.STREAM:
222 in_r, in_w = os.pipe()
223 kwargs["stdin"] = in_r
224 pipe_fds.extend((in_r, in_w))
225 to_close.append(in_r)
226 self.stdin = PipeIOStream(in_w)
227 if kwargs.get("stdout") is Subprocess.STREAM:
228 out_r, out_w = os.pipe()
229 kwargs["stdout"] = out_w
230 pipe_fds.extend((out_r, out_w))
231 to_close.append(out_w)
232 self.stdout = PipeIOStream(out_r)
233 if kwargs.get("stderr") is Subprocess.STREAM:
234 err_r, err_w = os.pipe()
235 kwargs["stderr"] = err_w
236 pipe_fds.extend((err_r, err_w))
237 to_close.append(err_w)
238 self.stderr = PipeIOStream(err_r)
239 try:
240 self.proc = subprocess.Popen(*args, **kwargs)
241 except:
242 for fd in pipe_fds:
243 os.close(fd)
244 raise

Callers 8

test_subprocessMethod · 0.90
test_close_stdinMethod · 0.90
test_stderrMethod · 0.90
test_sigchildMethod · 0.90
test_sigchild_futureMethod · 0.90
test_sigchild_signalMethod · 0.90

Calls

no outgoing calls

Tested by 8

test_subprocessMethod · 0.72
test_close_stdinMethod · 0.72
test_stderrMethod · 0.72
test_sigchildMethod · 0.72
test_sigchild_futureMethod · 0.72
test_sigchild_signalMethod · 0.72