# Start child process using fork
def __init__(self, process_obj):
util._flush_std_streams()
self._launch(process_obj)
def duplicate_for_child(self, fd):
def poll(self, flag=os.WNOHANG):
if self.returncode is None:
pid, sts = os.waitpid(self.pid, flag)
# Child process not yet created. See #1731717
# e.errno == errno.ECHILD == 10
self.returncode = -os.WTERMSIG(sts)
assert os.WIFEXITED(sts), "Status is {:n}".format(sts)
self.returncode = os.WEXITSTATUS(sts)
def wait(self, timeout=None):
if self.returncode is None:
from multiprocessing.connection import wait
if not wait([self.sentinel], timeout):
# This shouldn't block if wait() returned successfully.
return self.poll(os.WNOHANG if timeout == 0.0 else 0)
def _send_signal(self, sig):
if self.returncode is None:
except ProcessLookupError:
if self.wait(timeout=0.1) is None:
self._send_signal(signal.SIGTERM)
self._send_signal(signal.SIGKILL)
def _launch(self, process_obj):
parent_r, child_w = os.pipe()
child_r, parent_w = os.pipe()
code = process_obj._bootstrap(parent_sentinel=child_r)
self.finalizer = util.Finalize(self, util.close_fds,
if self.finalizer is not None: