<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Jul 26, 2013 at 3:23 PM, Antoine Pitrou <span dir="ltr"><<a href="mailto:solipsis@pitrou.net" target="_blank">solipsis@pitrou.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Sat, 27 Jul 2013 00:18:40 +0200<br>
Victor Stinner <<a href="mailto:victor.stinner@gmail.com">victor.stinner@gmail.com</a>> wrote:<br>
> 2013/7/26 Antoine Pitrou <<a href="mailto:solipsis@pitrou.net">solipsis@pitrou.net</a>>:<br>
> > On Fri, 26 Jul 2013 22:17:47 +0200<br>
> >> """<br>
> >> On Linux, setting the close-on-flag has a low overhead on<br>
> >> performances. Results of bench_cloexec.py on Linux 3.6:<br>
> >><br>
> >> - close-on-flag not set: 7.8 us<br>
> >> - O_CLOEXEC: 1% slower (7.9 us)<br>
> >> - ioctl(): 3% slower (8.0 us)<br>
> >> - fcntl(): 3% slower (8.0 us)<br>
> >> """<br>
> ><br>
> > You aren't answering my question: slower than what?<br>
><br>
> Ah, you didn't understand the labels. bench_cloexec.py runs a<br>
> benchmark on os.open(path, os.O_RDONLY, cloexec=False) and<br>
> os.open(path, os.O_RDONLY, cloexec=True) with different implementation<br>
> of making the file descriptor non-inheritable.<br>
><br>
> close-on-flag not set: 7.8 us<br>
> => C code: open(path, O_RDONLY)<br>
><br>
> O_CLOEXEC: 1% slower (7.9 us)<br>
> => C code: open(path, O_RDONLY|CLOEXEC)<br>
> => 1% slower than open(path, O_RDONLY)<br>
><br>
> ioctl(): 3% slower (8.0 us)<br>
> => C code: fd=open(path, O_RDONLY); ioctl(fd, FIOCLEX, 0)<br>
> => 3% slower than open(path, O_RDONLY)<br>
><br>
> fcntl(): 3% slower (8.0 us)<br>
> => C code: fd=open(path, O_RDONLY); flags = fcntl(fd, F_GETFD);<br>
> fcntl(fd, F_SETFD, flags | FD_CLOEXEC)<br>
> => 3% slower than open(path, O_RDONLY)<br>
<br>
</div></div>Ok, so I think this it is a totally reasonable compromise.<br>
<br>
People who bother about a 3% slowdown when calling os.open() can<br>
optimize the hell out of their code using Cython for all I care :-)<br>
<br></blockquote><div><br></div><div>+1 ;)</div><div><br></div><div>and +1 for making the sane default of noinherit / cloexec / whatever-others-call-it by default for all fds/handles ever opened by Python. It stops ignoring the issue (ie: the status quo of matching the default behavior of C as defined in the 1970s)... That is a GOOD thing. :)</div>
<div><br></div><div>-gps</div></div></div></div>