annotate Lib/dummy_thread.py @ 58765:2ba7677bfa95 legacy-trunk

testCopysign was defined twice in test_math; combine the definitions
author Mark Dickinson <dickinsm@gmail.com>
date Sat, 06 Feb 2010 23:11:25 +0000
parents 75658543b919
children 787b969d37f0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26890
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 """Drop-in replacement for the thread module.
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
2
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 Meant to be used as a brain-dead substitute so that threaded code does
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 not need to be rewritten for when the thread module is not present.
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
5
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 Suggested usage is::
27507
d9d57f5f98cd Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 26890
diff changeset
7
26890
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 try:
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 import thread
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 except ImportError:
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 import dummy_thread as thread
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
12
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 """
40716
1163f55dad95 Remove specific mention of my name and email address from modules. Not really
Brett Cannon <bcannon@gmail.com>
parents: 38799
diff changeset
14 # Exports only things specified by thread documentation;
1163f55dad95 Remove specific mention of my name and email address from modules. Not really
Brett Cannon <bcannon@gmail.com>
parents: 38799
diff changeset
15 # skipping obsolete synonyms allocate(), start_new(), exit_thread().
26890
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 __all__ = ['error', 'start_new_thread', 'exit', 'get_ident', 'allocate_lock',
29446
e9953b399d55 dummy_thread modified to have interrupt_main and to behave appropriately when
Brett Cannon <bcannon@gmail.com>
parents: 27507
diff changeset
17 'interrupt_main', 'LockType']
26890
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
18
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 import traceback as _traceback
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
20
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 class error(Exception):
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 """Dummy implementation of thread.error."""
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
23
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 def __init__(self, *args):
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 self.args = args
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
26
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 def start_new_thread(function, args, kwargs={}):
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 """Dummy implementation of thread.start_new_thread().
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
29
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 Compatibility is maintained by making sure that ``args`` is a
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 tuple and ``kwargs`` is a dictionary. If an exception is raised
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 and it is SystemExit (which can be done by thread.exit()) it is
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 caught and nothing is done; all other exceptions are printed out
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 by using traceback.print_exc().
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
35
29446
e9953b399d55 dummy_thread modified to have interrupt_main and to behave appropriately when
Brett Cannon <bcannon@gmail.com>
parents: 27507
diff changeset
36 If the executed function calls interrupt_main the KeyboardInterrupt will be
e9953b399d55 dummy_thread modified to have interrupt_main and to behave appropriately when
Brett Cannon <bcannon@gmail.com>
parents: 27507
diff changeset
37 raised when the function returns.
e9953b399d55 dummy_thread modified to have interrupt_main and to behave appropriately when
Brett Cannon <bcannon@gmail.com>
parents: 27507
diff changeset
38
26890
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 """
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 if type(args) != type(tuple()):
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 raise TypeError("2nd arg must be a tuple")
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 if type(kwargs) != type(dict()):
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 raise TypeError("3rd arg must be a dict")
29447
2cb969ffe1bf Cause calling interrupt_main in main thread raise KeyboardInterrupt instantly.
Brett Cannon <bcannon@gmail.com>
parents: 29446
diff changeset
44 global _main
2cb969ffe1bf Cause calling interrupt_main in main thread raise KeyboardInterrupt instantly.
Brett Cannon <bcannon@gmail.com>
parents: 29446
diff changeset
45 _main = False
26890
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 try:
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 function(*args, **kwargs)
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 except SystemExit:
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 pass
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 except:
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 _traceback.print_exc()
29447
2cb969ffe1bf Cause calling interrupt_main in main thread raise KeyboardInterrupt instantly.
Brett Cannon <bcannon@gmail.com>
parents: 29446
diff changeset
52 _main = True
2cb969ffe1bf Cause calling interrupt_main in main thread raise KeyboardInterrupt instantly.
Brett Cannon <bcannon@gmail.com>
parents: 29446
diff changeset
53 global _interrupt
29446
e9953b399d55 dummy_thread modified to have interrupt_main and to behave appropriately when
Brett Cannon <bcannon@gmail.com>
parents: 27507
diff changeset
54 if _interrupt:
e9953b399d55 dummy_thread modified to have interrupt_main and to behave appropriately when
Brett Cannon <bcannon@gmail.com>
parents: 27507
diff changeset
55 _interrupt = False
e9953b399d55 dummy_thread modified to have interrupt_main and to behave appropriately when
Brett Cannon <bcannon@gmail.com>
parents: 27507
diff changeset
56 raise KeyboardInterrupt
26890
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
57
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 def exit():
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 """Dummy implementation of thread.exit()."""
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 raise SystemExit
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
61
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 def get_ident():
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 """Dummy implementation of thread.get_ident().
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
64
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 Since this module should only be used when threadmodule is not
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 available, it is safe to assume that the current process is the
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 only thread. Thus a constant can be safely returned.
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 """
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 return -1
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
70
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
71 def allocate_lock():
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
72 """Dummy implementation of thread.allocate_lock()."""
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
73 return LockType()
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
74
38794
f7d23bca599f Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 38592
diff changeset
75 def stack_size(size=None):
f7d23bca599f Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 38592
diff changeset
76 """Dummy implementation of thread.stack_size()."""
f7d23bca599f Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 38592
diff changeset
77 if size is not None:
38799
5d622e483fcc fix exception usage
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 38794
diff changeset
78 raise error("setting thread stack size not supported")
38794
f7d23bca599f Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 38592
diff changeset
79 return 0
f7d23bca599f Patch #1454481: Make thread stack size runtime tunable.
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 38592
diff changeset
80
26890
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
81 class LockType(object):
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
82 """Class implementing dummy implementation of thread.LockType.
27507
d9d57f5f98cd Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 26890
diff changeset
83
26890
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
84 Compatibility is maintained by maintaining self.locked_status
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
85 which is a boolean that stores the state of the lock. Pickling of
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
86 the lock, though, should not be done since if the thread module is
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 then used with an unpickled ``lock()`` from here problems could
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
88 occur from this class not having atomic methods.
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
89
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
90 """
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
91
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
92 def __init__(self):
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
93 self.locked_status = False
27507
d9d57f5f98cd Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 26890
diff changeset
94
26890
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
95 def acquire(self, waitflag=None):
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
96 """Dummy implementation of acquire().
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
97
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
98 For blocking calls, self.locked_status is automatically set to
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
99 True and returned appropriately based on value of
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
100 ``waitflag``. If it is non-blocking, then the value is
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
101 actually checked and not set if it is already acquired. This
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
102 is all done so that threading.Condition's assert statements
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
103 aren't triggered and throw a little fit.
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
104
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
105 """
47940
beb0ff5a2a0f dummy_thread.acquire() would return None if no waitflag argument was given. It
Brett Cannon <bcannon@gmail.com>
parents: 40716
diff changeset
106 if waitflag is None or waitflag:
26890
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
107 self.locked_status = True
47940
beb0ff5a2a0f dummy_thread.acquire() would return None if no waitflag argument was given. It
Brett Cannon <bcannon@gmail.com>
parents: 40716
diff changeset
108 return True
beb0ff5a2a0f dummy_thread.acquire() would return None if no waitflag argument was given. It
Brett Cannon <bcannon@gmail.com>
parents: 40716
diff changeset
109 else:
26890
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
110 if not self.locked_status:
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
111 self.locked_status = True
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
112 return True
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
113 else:
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
114 return False
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
115
37255
f4ca03b87160 dummy_thread needs to support PEP 343 too.
Phillip J. Eby <pje@telecommunity.com>
parents: 29447
diff changeset
116 __enter__ = acquire
f4ca03b87160 dummy_thread needs to support PEP 343 too.
Phillip J. Eby <pje@telecommunity.com>
parents: 29447
diff changeset
117
f4ca03b87160 dummy_thread needs to support PEP 343 too.
Phillip J. Eby <pje@telecommunity.com>
parents: 29447
diff changeset
118 def __exit__(self, typ, val, tb):
f4ca03b87160 dummy_thread needs to support PEP 343 too.
Phillip J. Eby <pje@telecommunity.com>
parents: 29447
diff changeset
119 self.release()
f4ca03b87160 dummy_thread needs to support PEP 343 too.
Phillip J. Eby <pje@telecommunity.com>
parents: 29447
diff changeset
120
26890
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 def release(self):
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 """Release the dummy lock."""
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
123 # XXX Perhaps shouldn't actually bother to test? Could lead
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
124 # to problems for complex, threaded code.
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 if not self.locked_status:
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
126 raise error
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
127 self.locked_status = False
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
128 return True
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
129
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
130 def locked(self):
8053bc0b8bb5 Brett Cannon's dummy_thread and dummy_threading modules (SF patch
Guido van Rossum <guido@python.org>
parents:
diff changeset
131 return self.locked_status
29446
e9953b399d55 dummy_thread modified to have interrupt_main and to behave appropriately when
Brett Cannon <bcannon@gmail.com>
parents: 27507
diff changeset
132
29447
2cb969ffe1bf Cause calling interrupt_main in main thread raise KeyboardInterrupt instantly.
Brett Cannon <bcannon@gmail.com>
parents: 29446
diff changeset
133 # Used to signal that interrupt_main was called in a "thread"
29446
e9953b399d55 dummy_thread modified to have interrupt_main and to behave appropriately when
Brett Cannon <bcannon@gmail.com>
parents: 27507
diff changeset
134 _interrupt = False
29447
2cb969ffe1bf Cause calling interrupt_main in main thread raise KeyboardInterrupt instantly.
Brett Cannon <bcannon@gmail.com>
parents: 29446
diff changeset
135 # True when not executing in a "thread"
2cb969ffe1bf Cause calling interrupt_main in main thread raise KeyboardInterrupt instantly.
Brett Cannon <bcannon@gmail.com>
parents: 29446
diff changeset
136 _main = True
29446
e9953b399d55 dummy_thread modified to have interrupt_main and to behave appropriately when
Brett Cannon <bcannon@gmail.com>
parents: 27507
diff changeset
137
e9953b399d55 dummy_thread modified to have interrupt_main and to behave appropriately when
Brett Cannon <bcannon@gmail.com>
parents: 27507
diff changeset
138 def interrupt_main():
e9953b399d55 dummy_thread modified to have interrupt_main and to behave appropriately when
Brett Cannon <bcannon@gmail.com>
parents: 27507
diff changeset
139 """Set _interrupt flag to True to have start_new_thread raise
e9953b399d55 dummy_thread modified to have interrupt_main and to behave appropriately when
Brett Cannon <bcannon@gmail.com>
parents: 27507
diff changeset
140 KeyboardInterrupt upon exiting."""
29447
2cb969ffe1bf Cause calling interrupt_main in main thread raise KeyboardInterrupt instantly.
Brett Cannon <bcannon@gmail.com>
parents: 29446
diff changeset
141 if _main:
2cb969ffe1bf Cause calling interrupt_main in main thread raise KeyboardInterrupt instantly.
Brett Cannon <bcannon@gmail.com>
parents: 29446
diff changeset
142 raise KeyboardInterrupt
2cb969ffe1bf Cause calling interrupt_main in main thread raise KeyboardInterrupt instantly.
Brett Cannon <bcannon@gmail.com>
parents: 29446
diff changeset
143 else:
2cb969ffe1bf Cause calling interrupt_main in main thread raise KeyboardInterrupt instantly.
Brett Cannon <bcannon@gmail.com>
parents: 29446
diff changeset
144 global _interrupt
2cb969ffe1bf Cause calling interrupt_main in main thread raise KeyboardInterrupt instantly.
Brett Cannon <bcannon@gmail.com>
parents: 29446
diff changeset
145 _interrupt = True