Commit 3e5fdfe5 authored by Gregory P. Smith's avatar Gregory P. Smith

Fixes issue1336 - a race condition could occur when forking if the gc

kicked in during the critical section.  solution: disable gc during
that section.  Patch contributed by jpa and updated by me to cover the
race condition still existing what therve from twistedmatrix pointed
out (already seen and fixed in twisted's own subprocess code).
parent f36c37c0
......@@ -356,6 +356,7 @@ mswindows = (sys.platform == "win32")
import os
import types
import traceback
import gc
# Exception classes used by this module.
class CalledProcessError(Exception):
......@@ -994,7 +995,17 @@ class Popen(object):
errpipe_read, errpipe_write = os.pipe()
self._set_cloexec_flag(errpipe_write)
gc_was_enabled = gc.isenabled()
# Disable gc to avoid bug where gc -> file_dealloc ->
# write to stderr -> hang. http://bugs.python.org/issue1336
gc.disable()
try:
self.pid = os.fork()
except:
if gc_was_enabled:
gc.enable()
raise
else:
self._child_created = True
if self.pid == 0:
# Child
......@@ -1054,6 +1065,8 @@ class Popen(object):
os._exit(255)
# Parent
if gc_was_enabled:
gc.enable()
os.close(errpipe_write)
if p2cread is not None and p2cwrite is not None:
os.close(p2cread)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment