From f21fcd09c50d30ca99e9fa95f70dba481bd46f1b Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Sat, 26 Jul 2014 17:54:34 +0300 Subject: Accept optional lock object in Condition ctor (tulip issue #198) --- Lib/asyncio/locks.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'Lib/asyncio/locks.py') diff --git a/Lib/asyncio/locks.py b/Lib/asyncio/locks.py index 8d9e3b4dd9a..574e3618f27 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 -- cgit v1.2.3