[Python-checkins] r60104 - python/trunk/Lib/subprocess.py

Christian Heimes lists at cheimes.de
Sat Jan 19 22:17:05 CET 2008


gregory.p.smith wrote:
> Author: gregory.p.smith
> Date: Sat Jan 19 21:57:59 2008
> New Revision: 60104
> 
> Modified:
>    python/trunk/Lib/subprocess.py
> Log:
> 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).
> 
> 
> Modified: python/trunk/Lib/subprocess.py
> ==============================================================================
> --- python/trunk/Lib/subprocess.py	(original)
> +++ python/trunk/Lib/subprocess.py	Sat Jan 19 21:57:59 2008
> @@ -356,6 +356,7 @@
>  import os
>  import types
>  import traceback
> +import gc
>  
>  # Exception classes used by this module.
>  class CalledProcessError(Exception):
> @@ -994,66 +995,78 @@
>              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()

[lots of lines which may fail]

>  
>              # Parent
> +            if gc_was_enabled:
> +                gc.enable()
>              os.close(errpipe_write)
>              if p2cread is not None and p2cwrite is not None:
>                  os.close(p2cread)

I'd feel better if the large block is surrounded by a try/finally block
with finally: gc.enable()

Christian, the paranoid


More information about the Python-checkins mailing list