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

pitrou, re. test code: I actually started with the test code, so that part is 
done.

I opted to use a forked SocketServer rather than threads. I'm not an expert on 
the low-level details of a multi-threaded process receiving threads, but it 
seems to me like there's a chicken and egg issue here: suppose we have threadA 
(blocking on select()) and threadB (managing the test and doing something like 
os.kill(os.getpid(), SIGFOO). I think by definition the thread running when the 
signal is received is threadB (since it sent the signal), and I'm not sure 
threadA will be interrupted properly that way (threads are sneaky, now aren't 
they). So I cleaned up test_socketserver.py a bit, split it to a base test case 
and concrete test cases, and added a separate test case which uses os.fork() 
rather than threads and tests that way.

The attached patch is against recent py3k and includes both neologix's patch 
(adapted to py3k) and the added test code. If this looks good, I'll easily 
backport it to 2.x/trunk.

spiv, re. handling timeout in select: You're very right, and I'm not sure how 
we should handle it if we want to take the "untilConcludes" code that is 
currently shared between subprocess.py and socketserver.py and move it outside. 
For subprocess' and socketserver's specific cases, the naive implementation 
which doesn't handle timeouts is OK, because they don't use the timeout 
parameter anyway.

Moving it outside warrants more discussion. Remember this isn't just about 
select() - it's a general user-space-restarter for any of the myriad of "slow" 
system calls that might be interrupted. There is some tension between elegance 
and even feasibility of correct implementation vs. the wrapper hiding 
functionality of some of these system calls. You could argue that if the user 
of the wrapper is unhappy about the lost functionality, they can make their own 
wrapper. 

Unless we can reach a resolution quickly, my gut feeling is that the current 
patch should be applied as-is and this issue be closed. A new issue along the 
lines of "Extract duplicate interruption-restart code to a relevant module and 
review stdlib for unprotected select() calls" should be opened instead. Your 
thoughts?

----------
Added file: http://bugs.python.org/file16841/socketserver_eintr_py3k.diff

_______________________________________
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