summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio
diff options
context:
space:
mode:
authorAndrew Svetlov <andrew.svetlov@gmail.com>2014-07-26 14:54:34 (GMT)
committerAndrew Svetlov <andrew.svetlov@gmail.com>2014-07-26 14:54:34 (GMT)
commitf21fcd09c50d30ca99e9fa95f70dba481bd46f1b (patch)
tree1f73c8e8e6d7e8d5b3651f38239498d201efcdd5 /Lib/asyncio
parente254e53c833d39e1e479a16d7976a7726c0c1981 (diff)
downloadcpython-f21fcd09c50d30ca99e9fa95f70dba481bd46f1b.zip
cpython-f21fcd09c50d30ca99e9fa95f70dba481bd46f1b.tar.gz
cpython-f21fcd09c50d30ca99e9fa95f70dba481bd46f1b.tar.bz2
Accept optional lock object in Condition ctor (tulip issue #198)
Diffstat (limited to 'Lib/asyncio')
-rw-r--r--Lib/asyncio/locks.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/Lib/asyncio/locks.py b/Lib/asyncio/locks.py
index 8d9e3b4..574e361 100644
--- a/Lib/asyncio/locks.py
+++ b/Lib/asyncio/locks.py
@@ -255,14 +255,17 @@ class Condition:
A new Lock object is created and used as the underlying lock.
"""
- def __init__(self, *, loop=None):
+ def __init__(self, lock=None, *, loop=None):
if loop is not None:
self._loop = loop
else:
self._loop = events.get_event_loop()
- # Lock as an attribute as in threading.Condition.
- lock = Lock(loop=self._loop)
+ if lock is None:
+ lock = Lock(loop=self._loop)
+ elif lock._loop is not self._loop:
+ raise ValueError("loop argument must agree with lock")
+
self._lock = lock
# Export the lock's locked(), acquire() and release() methods.
self.locked = lock.locked