[Python-Dev] PEP 446: Open issues/questions

Richard Oudkerk shibturn at gmail.com
Fri Aug 2 10:16:07 CEST 2013


On 02/08/2013 1:21am, Victor Stinner wrote:
> 2013/7/30 Victor Stinner <victor.stinner at gmail.com>:
>> I would be nice to have a "pass_handles" on Windows.
>
> I'm not sure that it's possible to implement this atomically. It's
> probably better to leave the application to choose how the inheritance
> is defined.
>
> Example:
>
> for handle in handles:
>      os.set_inheritable(handle, True)
> subprocess.call(...)
> for handle in handles:
>      os.set_inheritable(handle, False)
>
> This example is safe if the application has a single thread (if a
> single thread spawn new programs). Making handles non-inheritable
> again may be useless.

If we have a recursive lock which is always held when Python starts a 
process then you could write:

   with subprocess.getlock():
       for handle in handles:
           os.set_inheritable(handle, True)
       subprocess.call(...)
       for handle in handles:
           os.set_inheritable(handle, False)

This should be used by fork() and multiprocessing too.

-- 
Richard



More information about the Python-Dev mailing list