msg43054 - (view) |
Author: Michael Stone (mbrierst) |
Date: 2003-03-19 17:46 |
This patch attempts to fix raw_input so it can be interrupted by signals. In the process it allows SIGINT handling to be honored by raw_input. (right now SIGINT always interrupts regardless of any installed handlers) Effects: Signals are handled with their installed handlers and when those handlers raise exceptions those exceptions are raised by raw_input. If an exception is not raised, raw_input continues collecting input as if nothing had happened. This can be problematic if the signal causes output to appear on the screen, messing up the input line, or if someone using the readline module was in the middle of a complex operation, like a reverse search, in which case that operation will be cancelled. It would be easy to instead print a message ("Signal Interruption") and continue input on a new line for the readline library, but this couldn't happen in myreadline.c as we can't retrieve the partially entered input. Backwards compatibility: This patch requires the readline handler (either call_readline or PyOS_StdioReadline generally) to be called while holding the global interpreter lock. It is then responsible for releasing the GIL before doing blocking input. This will cause problems for anyone who has written an extension that installs a custom readline handler. In python code, anyone using signals and expecting raw_input not to be interrupted by them will have problems (but this seems unlikely). |
|
|
msg55698 - (view) |
Author: Georg Brandl (georg.brandl) *  |
Date: 2007-09-06 15:13 |
Set as superseder of #685846 and #1113. |
|
|
msg87650 - (view) |
Author: Michael Stone (mbrierst) |
Date: 2009-05-12 18:29 |
ajaksu2 has uploaded a file called "test.py" that seems to have nothing to do with this issue, unless I'm misunderstanding something. I don't see any call to readline in the uploaded file at all. Perhaps the file you meant to upload, was the one from issue 1113? http://bugs.python.org/file8392/test.py |
|
|
msg87652 - (view) |
Author: Daniel Diniz (ajaksu2) *  |
Date: 2009-05-12 18:36 |
Oops, sorry! I should know better than to name scripts test.py: the upload failed and when I realized that (after some time), test.py was already something else. Thanks for catching this instance of PEBKAC, Michael :) |
|
|
msg114227 - (view) |
Author: Mark Lawrence (BreamoreBoy) * |
Date: 2010-08-18 14:44 |
Can this still be reproduced on an appropriate box or can it be closed or what? |
|
|
msg114229 - (view) |
Author: ysj.ray (ysj.ray) |
Date: 2010-08-18 15:09 |
I seems this has been fixed already, at least on my python 2.7 on linux. |
|
|
msg114316 - (view) |
Author: Michael Stone (mbrierst) |
Date: 2010-08-19 01:07 |
Wow, you wait 3/4 of a decade or so and the status of these bugs does tend to change on you. I'm not sure it's fixed, but it is different. Here's a test script for you: import readline import signal def handle(a,b): print "received signal" signal.signal(signal.SIGALRM, handle) signal.alarm(5) name = raw_input('Please enter your name within 5 seconds: ') print name The behavior of this script as is, since at least python 2.5 or so, is after 5 seconds to run the signal handler and then keep waiting for input (assuming you've got readline on your box of course). I like this behavior, everything seems good to me so far. Now comment out the "import readline", and suddenly you're getting an EOFError after the signal handler runs normally. Still better than it used to be in 2003, but I'm not sure if this inconsistency is okay or not. Now let's throw another wrench in the system. Raise an exception in the signal handler. Suddenly both are consistent again with and without readline, both raising the exception from the signal handler. Sounds good to me. So I guess someone has to decide, is this EOFError a new bug? Or is this inconsistency acceptable and/or too hard to fix? I haven't looked at the code in forever, so I can't speak for how hard it would be to fix. |
|
|
msg116636 - (view) |
Author: Mark Lawrence (BreamoreBoy) * |
Date: 2010-09-16 23:01 |
Can someone please comment on as I'm out of my depth here, thanks. |
|
|
msg122050 - (view) |
Author: Ned Deily (ned.deily) *  |
Date: 2010-11-22 00:43 |
(Noted in passing: Issue9867 may be relevant here.) |
|
|
msg190038 - (view) |
Author: Mark Lawrence (BreamoreBoy) * |
Date: 2013-05-26 00:19 |
Bump this as IIRC other issues discussing SIGINT handling have been processed recently. |
|
|
msg190114 - (view) |
Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) *  |
Date: 2013-05-26 20:56 |
Closing as fixed. I tested with python2.7 and 3.2, both with and without a readline module. Behavior is consistent and looks correct to me: the signal is honored (message printed after 5s), and does not stop the raw_input(), except when it raises an exception, in which case the command exits and the exception is propagated. |
|
|