summaryrefslogtreecommitdiffstats
path: root/Lib/dummy_thread.py
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2003-06-13 23:44:35 (GMT)
committerBrett Cannon <bcannon@gmail.com>2003-06-13 23:44:35 (GMT)
commit4e64d78bbb961672ee324db234c70320ed4db6d5 (patch)
treec5aa27b4e8b98693b93bfdf01e42ea1ac007c608 /Lib/dummy_thread.py
parent93e8e5492402d55e0c0c4b08ff213783f5891561 (diff)
downloadcpython-4e64d78bbb961672ee324db234c70320ed4db6d5.zip
cpython-4e64d78bbb961672ee324db234c70320ed4db6d5.tar.gz
cpython-4e64d78bbb961672ee324db234c70320ed4db6d5.tar.bz2
dummy_thread modified to have interrupt_main and to behave appropriately when
called. Added announcement in Misc/NEWS for thread.interrupt_main and mention of dummy_thread's change.
Diffstat (limited to 'Lib/dummy_thread.py')
-rw-r--r--Lib/dummy_thread.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/Lib/dummy_thread.py b/Lib/dummy_thread.py
index e4bf05a..7da51b9 100644
--- a/Lib/dummy_thread.py
+++ b/Lib/dummy_thread.py
@@ -17,7 +17,7 @@ __email__ = "brett@python.org"
# Exports only things specified by thread documentation
# (skipping obsolete synonyms allocate(), start_new(), exit_thread())
__all__ = ['error', 'start_new_thread', 'exit', 'get_ident', 'allocate_lock',
- 'LockType']
+ 'interrupt_main', 'LockType']
import traceback as _traceback
@@ -36,6 +36,9 @@ def start_new_thread(function, args, kwargs={}):
caught and nothing is done; all other exceptions are printed out
by using traceback.print_exc().
+ If the executed function calls interrupt_main the KeyboardInterrupt will be
+ raised when the function returns.
+
"""
if type(args) != type(tuple()):
raise TypeError("2nd arg must be a tuple")
@@ -47,6 +50,10 @@ def start_new_thread(function, args, kwargs={}):
pass
except:
_traceback.print_exc()
+ if _interrupt:
+ global _interrupt
+ _interrupt = False
+ raise KeyboardInterrupt
def exit():
"""Dummy implementation of thread.exit()."""
@@ -114,3 +121,12 @@ class LockType(object):
def locked(self):
return self.locked_status
+
+
+_interrupt = False
+
+def interrupt_main():
+ """Set _interrupt flag to True to have start_new_thread raise
+ KeyboardInterrupt upon exiting."""
+ global _interrupt
+ _interrupt = True