Yaniv Aknin <yaniv.ak...@gmail.com> added the comment:

First, let me cast my vote in favour of leaving select() itself alone, it's 
excessive to fix this issue with changing select().

Second, while exarkun's comments are accurate, I understand where pitrou is 
coming from. EINTR is not a pathological case, but it's not commonplace, 
either. I believe that on modern Unices (I tried Linux and OpenSolaris), the 
default handler for SIGCHLD will restart interrupted calls. By default, SIGUSR1 
and most sane others, will kill the process anyway. So I can understand the 
purity of the argument that if a process sets a signal handler, it might just 
as well set SA_RESTART and be done with it.

That said, Imagine I write a forking server with SocketServer which sets a 
signal handler for SIGCHLD, and I don't set SA_RESTART because I don't think I 
need to. I believe this is a valid real-world scenario where (a) I don't expect 
an EINTER-related exception to be raised from SocketServer, (b) SocketServer 
can actually do something about it, and (c) I doubt the old EINTR behaviour is 
relied upon by anyone (now I'm /certain/ someone relying on this will 
pop-up...). I think its a safer bet on behalf of SocketServer (and subprocess, 
etc) to use something like untilConcludes.

If we agree so far, I believe that an implementation of untilConcludes *should* 
be added to stdlib ("signal.restartable_call", anyone?). If people agree, I'd 
be happy to produce the patch (trunk+py3k, doc+test). Other than SocketServer 
and subprocess, anything else that should use "untilConcludes"?

Finally, to answer pitrou's second question, I'm pretty sure untilConcludes as 
presented will not hurt other signal handlers. The interrupt handler will be 
executed before returning to untilConcludes' loop and manually restarting the 
call, so KeyboardInterrupt (or anything else signalistic) will behave as 
expected.

I'm attaching a toy 3.x program to play with select() and EINTR, I used it in 
writing this comment. Gee, it even has an OptionParser CLI to save you some 
commenting-out.

----------
nosy: +Yaniv.Aknin
Added file: http://bugs.python.org/file16813/eintr_safety.py

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue7978>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to