summaryrefslogtreecommitdiffstats
path: root/Lib/dummy_thread.py
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2003-06-13 23:56:32 (GMT)
committerBrett Cannon <bcannon@gmail.com>2003-06-13 23:56:32 (GMT)
commit91012fe9b58b9dff2298aad453804023d557447b (patch)
tree28c6a48ff21d97783760a06eee1e1db62e2b21fe /Lib/dummy_thread.py
parent4e64d78bbb961672ee324db234c70320ed4db6d5 (diff)
downloadcpython-91012fe9b58b9dff2298aad453804023d557447b.zip
cpython-91012fe9b58b9dff2298aad453804023d557447b.tar.gz
cpython-91012fe9b58b9dff2298aad453804023d557447b.tar.bz2
Cause calling interrupt_main in main thread raise KeyboardInterrupt instantly.
Diffstat (limited to 'Lib/dummy_thread.py')
-rw-r--r--Lib/dummy_thread.py16
1 files changed, 12 insertions, 4 deletions
diff --git a/Lib/dummy_thread.py b/Lib/dummy_thread.py
index 7da51b9..fb3abbf 100644
--- a/Lib/dummy_thread.py
+++ b/Lib/dummy_thread.py
@@ -44,14 +44,17 @@ def start_new_thread(function, args, kwargs={}):
raise TypeError("2nd arg must be a tuple")
if type(kwargs) != type(dict()):
raise TypeError("3rd arg must be a dict")
+ global _main
+ _main = False
try:
function(*args, **kwargs)
except SystemExit:
pass
except:
_traceback.print_exc()
+ _main = True
+ global _interrupt
if _interrupt:
- global _interrupt
_interrupt = False
raise KeyboardInterrupt
@@ -122,11 +125,16 @@ class LockType(object):
def locked(self):
return self.locked_status
-
+# Used to signal that interrupt_main was called in a "thread"
_interrupt = False
+# True when not executing in a "thread"
+_main = True
def interrupt_main():
"""Set _interrupt flag to True to have start_new_thread raise
KeyboardInterrupt upon exiting."""
- global _interrupt
- _interrupt = True
+ if _main:
+ raise KeyboardInterrupt
+ else:
+ global _interrupt
+ _interrupt = True