summaryrefslogtreecommitdiffstats
path: root/Lib/threading.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-03-31 21:06:30 (GMT)
committerBenjamin Peterson <benjamin@python.org>2009-03-31 21:06:30 (GMT)
commitbd9dd31abdb81c81242aa9ab081d90db17eef0c0 (patch)
tree845b88b5899cd7f7929fd13bcd6b8cc6b591f0ae /Lib/threading.py
parent186188d89dc1069f1cfd64811fe8e92f0c9d6774 (diff)
downloadcpython-bd9dd31abdb81c81242aa9ab081d90db17eef0c0.zip
cpython-bd9dd31abdb81c81242aa9ab081d90db17eef0c0.tar.gz
cpython-bd9dd31abdb81c81242aa9ab081d90db17eef0c0.tar.bz2
take the usual lock precautions around _active_limbo_lock
Diffstat (limited to 'Lib/threading.py')
-rw-r--r--Lib/threading.py34
1 files changed, 13 insertions, 21 deletions
diff --git a/Lib/threading.py b/Lib/threading.py
index cc2be1b..28a8a2f 100644
--- a/Lib/threading.py
+++ b/Lib/threading.py
@@ -466,9 +466,8 @@ class Thread(_Verbose):
raise RuntimeError("thread already started")
if __debug__:
self._note("%s.start(): starting thread", self)
- _active_limbo_lock.acquire()
- _limbo[self] = self
- _active_limbo_lock.release()
+ with _active_limbo_lock:
+ _limbo[self] = self
_start_new_thread(self.__bootstrap, ())
self.__started.wait()
@@ -505,10 +504,9 @@ class Thread(_Verbose):
try:
self.__ident = _get_ident()
self.__started.set()
- _active_limbo_lock.acquire()
- _active[self.__ident] = self
- del _limbo[self]
- _active_limbo_lock.release()
+ with _active_limbo_lock:
+ _active[self.__ident] = self
+ del _limbo[self]
if __debug__:
self._note("%s.__bootstrap(): thread started", self)
@@ -735,9 +733,8 @@ class _MainThread(Thread):
def __init__(self):
Thread.__init__(self, name="MainThread")
self._Thread__started.set()
- _active_limbo_lock.acquire()
- _active[_get_ident()] = self
- _active_limbo_lock.release()
+ with _active_limbo_lock:
+ _active[_get_ident()] = self
def _set_daemon(self):
return False
@@ -781,9 +778,8 @@ class _DummyThread(Thread):
del self._Thread__block
self._Thread__started.set()
- _active_limbo_lock.acquire()
- _active[_get_ident()] = self
- _active_limbo_lock.release()
+ with _active_limbo_lock:
+ _active[_get_ident()] = self
def _set_daemon(self):
return True
@@ -804,18 +800,14 @@ def currentThread():
current_thread = currentThread
def activeCount():
- _active_limbo_lock.acquire()
- count = len(_active) + len(_limbo)
- _active_limbo_lock.release()
- return count
+ with _active_limbo_lock:
+ return len(_active) + len(_limbo)
active_count = activeCount
def enumerate():
- _active_limbo_lock.acquire()
- active = _active.values() + _limbo.values()
- _active_limbo_lock.release()
- return active
+ with _active_limbo_lock:
+ return _active.values() + _limbo.values()
from thread import stack_size