Skip to content

Commit 42dd575

Browse files
committed
Merge tjstum/master: Allow multiple calls to loop.stop
2 parents d300ff8 + 333cb6e commit 42dd575

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

newsfragments/58.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Calling ``loop.stop`` manually no longer causes a deadlock when
2+
exiting the context of ``trio_asyncio.open_loop``

tests/test_misc.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ def close_no_stop():
2626
await trio.sleep(0.1)
2727
await loop.wait_closed()
2828

29+
@pytest.mark.trio
30+
async def test_too_many_stops(self):
31+
with trio.move_on_after(1) as scope:
32+
async with trio_asyncio.open_loop() as loop:
33+
await trio.hazmat.checkpoint()
34+
loop.stop()
35+
assert not scope.cancelled_caught, \
36+
"Possible deadlock after manual call to loop.stop"
37+
2938
@pytest.mark.trio
3039
async def test_err1(self, loop):
3140
async def raise_err():

trio_asyncio/async_.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ def stop(self, waiter=None):
6060
6161
"""
6262
if waiter is None:
63-
waiter = trio.Event()
63+
if self._stop_wait is not None:
64+
return self._stop_wait
65+
waiter = self._stop_wait = trio.Event()
6466
else:
6567
waiter.clear()
6668

trio_asyncio/base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ def __init__(self, queue_len=None):
172172
self._stopped = trio.Event()
173173
self._stopped.set()
174174

175+
self._stop_wait = None
176+
175177
def __repr__(self):
176178
try:
177179
return "<%s running=%s at 0x%x>" % (

0 commit comments

Comments
 (0)