Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
a7121b83
Commit
a7121b83
authored
Jul 26, 2014
by
Andrew Svetlov
Browse files
Options
Browse Files
Download
Plain Diff
Accept optional lock object in Condition ctor (tulip issue #198)
parents
996b6714
f21fcd09
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
3 deletions
+18
-3
Lib/asyncio/locks.py
Lib/asyncio/locks.py
+6
-3
Lib/test/test_asyncio/test_locks.py
Lib/test/test_asyncio/test_locks.py
+12
-0
No files found.
Lib/asyncio/locks.py
View file @
a7121b83
...
...
@@ -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
...
...
Lib/test/test_asyncio/test_locks.py
View file @
a7121b83
...
...
@@ -656,6 +656,18 @@ class ConditionTests(test_utils.TestCase):
self
.
assertFalse
(
cond
.
locked
())
def
test_explicit_lock
(
self
):
lock
=
asyncio
.
Lock
(
loop
=
self
.
loop
)
cond
=
asyncio
.
Condition
(
lock
,
loop
=
self
.
loop
)
self
.
assertIs
(
lock
.
_loop
,
cond
.
_loop
)
def
test_ambiguous_loops
(
self
):
loop
=
self
.
new_test_loop
()
lock
=
asyncio
.
Lock
(
loop
=
self
.
loop
)
with
self
.
assertRaises
(
ValueError
):
asyncio
.
Condition
(
lock
,
loop
=
loop
)
class
SemaphoreTests
(
test_utils
.
TestCase
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment