Implement multiprocessing without inheriting parent file handle

Chris Angelico rosuav at gmail.com
Fri Mar 21 18:50:07 EDT 2014


On Sat, Mar 22, 2014 at 5:16 AM, Mark H Harris <harrismh777 at gmail.com> wrote:
> On 3/21/14 12:42 PM, Marko Rauhamaa wrote:
>>
>>    http://docs.python.org/3/library/subprocess.html#popen-constructor>
>
>
>> It's got the optional close_fds parameter, which is True by default.
>
>
>> IOW, you don't need to do anything if you use subprocess.Popen() to
>> start your child process. Incidentally, that's the preferred way.
>
>
> hi Marko, of course this depends on the environment; if unix-like, then yes,
> elif windows well, not so much...
>
> There are caveats about stdin, stdout, and stderr;  as well, there are
> caveats about passing fds between the two. Well, Popen() is implemented on
> unix and windows differently, so there is some study needed here if code is
> going to be run in both environments.

There were some recent changes, though, including making CLOEXEC the
default, which means that fork/exec on Unix will retain only the fds
you actually want.

ChrisA



More information about the Python-list mailing list