|
|
@ -2808,28 +2808,32 @@ class ExternalContext(object):
|
|
|
|
mitogen.parent_ids = self.config['parent_ids'][:]
|
|
|
|
mitogen.parent_ids = self.config['parent_ids'][:]
|
|
|
|
mitogen.parent_id = mitogen.parent_ids[0]
|
|
|
|
mitogen.parent_id = mitogen.parent_ids[0]
|
|
|
|
|
|
|
|
|
|
|
|
def _setup_stdio(self):
|
|
|
|
def _nullify_stdio(self):
|
|
|
|
# We must open this prior to closing stdout, otherwise it will recycle
|
|
|
|
"""
|
|
|
|
# a standard handle, the dup2() will not error, and on closing it, we
|
|
|
|
Open /dev/null to replace stdin, and stdout/stderr temporarily. In case
|
|
|
|
# lose a standrd handle, causing later code to again recycle a standard
|
|
|
|
of odd startup, assume we may be allocated a standard handle.
|
|
|
|
# handle.
|
|
|
|
"""
|
|
|
|
fp = open('/dev/null')
|
|
|
|
fd = os.open('/dev/null', os.O_RDWR)
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
for stdfd in (0, 1, 2):
|
|
|
|
|
|
|
|
if fd != stdfd:
|
|
|
|
|
|
|
|
os.dup2(fd, stdfd)
|
|
|
|
|
|
|
|
finally:
|
|
|
|
|
|
|
|
if fd not in (0, 1, 2):
|
|
|
|
|
|
|
|
os.close(fd)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _setup_stdio(self):
|
|
|
|
# When sys.stdout was opened by the runtime, overwriting it will not
|
|
|
|
# When sys.stdout was opened by the runtime, overwriting it will not
|
|
|
|
# cause close to be called. However when forking from a child that
|
|
|
|
# close FD 1. However when forking from a child that previously used
|
|
|
|
# previously used fdopen, overwriting it /will/ cause close to be
|
|
|
|
# fdopen(), overwriting it /will/ close FD 1. So we must swallow the
|
|
|
|
# called. So we must explicitly close it before IoLogger overwrites the
|
|
|
|
# close before IoLogger overwrites FD 1, otherwise its new FD 1 will be
|
|
|
|
# file descriptor, otherwise the assignment below will cause stdout to
|
|
|
|
# clobbered. Additionally, stdout must be replaced with /dev/null prior
|
|
|
|
# be closed.
|
|
|
|
# to stdout.close(), since if block buffering was active in the parent,
|
|
|
|
|
|
|
|
# any pre-fork buffered data will be flushed on close(), corrupting the
|
|
|
|
|
|
|
|
# connection to the parent.
|
|
|
|
|
|
|
|
self._nullify_stdio()
|
|
|
|
sys.stdout.close()
|
|
|
|
sys.stdout.close()
|
|
|
|
sys.stdout = None
|
|
|
|
self._nullify_stdio()
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
os.dup2(fp.fileno(), 0)
|
|
|
|
|
|
|
|
os.dup2(fp.fileno(), 1)
|
|
|
|
|
|
|
|
os.dup2(fp.fileno(), 2)
|
|
|
|
|
|
|
|
finally:
|
|
|
|
|
|
|
|
fp.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.stdout_log = IoLogger(self.broker, 'stdout', 1)
|
|
|
|
self.stdout_log = IoLogger(self.broker, 'stdout', 1)
|
|
|
|
self.stderr_log = IoLogger(self.broker, 'stderr', 2)
|
|
|
|
self.stderr_log = IoLogger(self.broker, 'stderr', 2)
|
|
|
|