[Python-Dev] PEP 433: Choose the default value of the new cloexec parameter

Nick Coghlan ncoghlan at gmail.com
Fri Jan 25 13:12:19 CET 2013


On Fri, Jan 25, 2013 at 10:07 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> On Fri, Jan 25, 2013 at 9:36 PM, Antoine Pitrou <solipsis at pitrou.net> wrote:
>> Le Fri, 25 Jan 2013 12:28:10 +0100,
>> Victor Stinner <victor.stinner at gmail.com> a écrit :
>>> Well, I don't know if sys.setdefaultcloexec() is a good idea or
>>> not :-)
>>
>> Both Charles-François and Nick have good points.
>> sys.setdefaultcloexec() is still useful if you want to force the
>> policy from a Python script's toplevel (it's more practical than
>> trying to fit a command-line option in the shebang line).
>
> Right, I'm only -0 on that aspect. It strikes me as somewhat dubious,
> but it's not obviously wrong the way a runtime equivalent of -Q or -R
> would be.

I just realised I could be converted to a +0 if the runtime time
switch could only be used to set the global default as "cloexec=True"
and couldn't be used to switch it back again (for testing purposes, if
you only want to switch it on temporarily, use a subprocess). That
way, as soon as you saw "sys.setdefaultcloexec()" at the beginning of
__main__, you'd know descriptors would only be inherited when
cloexec=False was set explicitly. If the default flag can also be
turned off globally (rather than being a one-way switch), then you
have no idea what libraries might do behind your back.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-Dev mailing list