MCPcopy
hub / github.com/tornadoweb/tornado / __init__

Method __init__

tornado/process.py:215–252  ·  view source on GitHub ↗
(self, *args: Any, **kwargs: Any)

Source from the content-addressed store, hash-verified

213 _waiting = {} # type: ignore
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
245 for fd in to_close:
246 os.close(fd)
247 self.pid = self.proc.pid
248 for attr in ["stdin", "stdout", "stderr"]:
249 if not hasattr(self, attr): # don't clobber streams set above
250 setattr(self, attr, getattr(self.proc, attr))
251 self._exit_callback = None # type: Optional[Callable[[int], None]]
252 self.returncode = None # type: Optional[int]
253
254 def set_exit_callback(self, callback: Callable[[int], None]) -> None:
255 """Runs ``callback`` when this process exits.

Callers

nothing calls this directly

Calls 5

PipeIOStreamClass · 0.90
currentMethod · 0.80
appendMethod · 0.80
getMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected