This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2011年01月05日 20:02 by Josh.Hanson, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Messages (5) | |||
|---|---|---|---|
| msg125463 - (view) | Author: Josh Hanson (Josh.Hanson) | Date: 2011年01月05日 20:02 | |
Example code: try: sys.stdin.read() except KeyboardInterrupt: print "Interrupted!" except: print "Some other exception?" finally: print "cleaning up..." print "done." Test: run the code and hit ctrl-c while the read is blocking. Expected behavior: program should print: Interrupted! cleaning up... done. Actual behavior: On linux, behaves as expected. On windows, prints: cleaning up... Traceback (most recent call last): File "filename.py", line 119, in <module> print 'cleaning up...' KeyboardInterrupt As you can see, neither of the "except" blocks was executed, and the "finally" block was erroneously interrupted. If I add one line inside the try block, as follows: try: sys.stdin.read() print "Done reading." ... [etc.] Then this is the output: Done reading. Interrupted! cleaning up... done. Here, the exception handler and finally block were executed as expected. This is still mildly unusual because the "done reading" print statement was reached when it probably shouldn't have been, but much more surprising because a newline was not printed after "Done reading.", and for some reason a space was. This has been tested and found in 32-bit python versions 2.6.5, 2.6.6, 2.7.1, and 3.1.3 on 64-bit Win7. |
|||
| msg131629 - (view) | Author: Devin Jeanpierre (Devin Jeanpierre) * | Date: 2011年03月21日 10:47 | |
I can confirm this behavior on 2.7. On 3.2 for me it prints "done.", but not "Interrupted!" |
|||
| msg131630 - (view) | Author: Devin Jeanpierre (Devin Jeanpierre) * | Date: 2011年03月21日 10:52 | |
Sorry, forgot to mention my system. 64-bit Windows 7. |
|||
| msg222888 - (view) | Author: Mark Lawrence (BreamoreBoy) * | Date: 2014年07月12日 22:05 | |
I can confirm that this works fine with 3.4.1 and 3.5.0a0. I don't run 2.7 any more so I don't know if this is fixed in later versions. |
|||
| msg382148 - (view) | Author: Irit Katriel (iritkatriel) * (Python committer) | Date: 2020年11月30日 13:39 | |
Python 2-only issue. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:10 | admin | set | github: 55046 |
| 2020年11月30日 13:39:56 | iritkatriel | set | status: open -> closed nosy: + iritkatriel messages: + msg382148 resolution: out of date stage: resolved |
| 2019年04月26日 19:06:49 | BreamoreBoy | set | nosy:
- BreamoreBoy |
| 2014年07月12日 22:13:49 | brian.curtin | set | nosy:
- brian.curtin |
| 2014年07月12日 22:05:07 | BreamoreBoy | set | nosy:
+ BreamoreBoy messages: + msg222888 versions: - Python 2.6, Python 3.1 |
| 2011年03月21日 10:52:12 | Devin Jeanpierre | set | nosy:
tim.golden, Devin Jeanpierre, brian.curtin, Josh.Hanson messages: + msg131630 |
| 2011年03月21日 10:47:04 | Devin Jeanpierre | set | nosy:
+ Devin Jeanpierre messages: + msg131629 |
| 2011年01月08日 06:04:09 | ned.deily | set | nosy:
+ tim.golden, brian.curtin |
| 2011年01月05日 20:02:04 | Josh.Hanson | create | |