(self, *args: Any, **kwargs: Any)
| 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. |
nothing calls this directly
no test coverage detected