Bugs item #1643738, was opened at 2007-01-24 13:14 Message generated for change (Comment added) made by tim_one You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1643738&group_id=5470
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Python Library Group: Python 2.5 Status: Open Resolution: None Priority: 5 Private: No Submitted By: Ulisses Furquim (ulissesf) Assigned to: Nobody/Anonymous (nobody) Summary: Problem with signals in a single-threaded application Initial Comment: I'm aware of the problems with signals in a multithreaded application, but I was using signals in a single-threaded application and noticed something that seemed wrong. Some signals were apparently being lost, but when another signal came in the python handler for that "lost" signal was being called. The problem seems to be inside the signal module. The global variable is_tripped is incremented every time a signal arrives. Then, inside PyErr_CheckSignals() (the pending call that calls all python handlers for signals that arrived) we can return immediately if is_tripped is zero. If is_tripped is different than zero, we loop through all signals calling the registered python handlers and after that we zero is_tripped. This seems to be ok, but what happens if a signal arrives after we've returned from its handler (or even after we've checked if that signal arrived) and before we zero is_tripped? I guess we can have a situation where is_tripped is zero but some Handlers[i].tripped are not. In fact, I've inserted some debugging output and could see that this actually happens and then I've written the attached test program to reproduce the problem. When we run this program, the handler for the SIGALRM isn't called after we return from the SIGIO handler. We return to our main loop and print 'Loop!' every 3 seconds aprox. and the SIGALRM handler is called only when another signal arrives (like when we hit Ctrl-C). ---------------------------------------------------------------------- >Comment By: Tim Peters (tim_one) Date: 2007-01-24 15:19 Message: Logged In: YES user_id=31435 Originator: NO Very nice! I'd add a description of the minor pathology remaining you described here as a code comment, at the point is_tripped is set to 0. If this stuff were screamingly obvious, the bug you fixed wouldn't have persisted for 15 years ;-) ---------------------------------------------------------------------- Comment By: Ulisses Furquim (ulissesf) Date: 2007-01-24 14:46 Message: Logged In: YES user_id=1578960 Originator: YES This patch is very simple. We didn't want to remove the is_tripped variable because PyErr_CheckSignals() is called several times directly so it would be nice if we could return immediately if no signals arrived. We also didn't want to run the registered handlers with any set of signals blocked. Thus, we thought of zeroing is_tripped as soon as we know there are signals to be handled (after we test is_tripped). This way most of the times we can return immediately because is_tripped is zero and we also don't need to block any signals. However, with this approach we can have a situation where is_tripped isn't zero but we have no signals to handle, so we'll loop through all signals and no registered handler will be called. This happens when we receive a signal after we zero is_tripped and before we check Handlers[i].tripped for that signal. Any comments? File Added: signals-v0.patch ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1643738&group_id=5470 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com