Use a with statement to ensure the threading.Condition is always released
```python
cond.acquire()
stuff()
cond.release()
```
is better spelt
```python
with cond:
stuff()
```
as the latter calls release even if an exception is thrown.
I don't think this causes any observable bugs right now.
@@ -105,12 +105,11 @@ class external_waiter(object):
return self._outcome.get()
def _propogate_state(self, new_state):
- self.cond.acquire()
+ with self.cond:
if _debug:
self._log.debug("Changing state from %d -> %d from %s" % (self.state, new_state, threading.current_thread()))
self.state = new_state
self.cond.notify()
- self.cond.release()
def thread_done(self):
if _debug:
@@ -135,8 +134,7 @@ class external_waiter(object):
if _debug:
self._log.debug("Waiting for the condition lock %s" % threading.current_thread())
- self.cond.acquire()
-
+ with self.cond:
while self.state == external_state.RUNNING:
self.cond.wait()
@@ -151,7 +149,6 @@ class external_waiter(object):
if self.state == external_state.INIT:
raise Exception("Thread %s state was not allowed from %s" % (self.thread, threading.current_thread()))
- self.cond.release()
return self.state
class Scheduler(object):
