Skip to content

Commit

Permalink
Use an event instead
Browse files Browse the repository at this point in the history
  • Loading branch information
tjstum committed Jan 12, 2022
1 parent bb02d15 commit 18a850c
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions trio/tests/test_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from .. import (
ClosedResourceError,
Event,
Process,
_core,
fail_after,
Expand Down Expand Up @@ -573,27 +574,29 @@ async def test_for_leaking_fds():


# regression test for #2209
@pytest.mark.skipif(not posix, reason="Regression test for Linux-only bug")
async def test_subprocess_pidfd_unnotified():
noticed_exit = None

async def wait_and_tell(proc) -> None:
nonlocal noticed_exit
noticed_exit = False
noticed_exit = Event()
await proc.wait()
noticed_exit = True
noticed_exit.set()

proc = await open_process(SLEEP(9999))
async with _core.open_nursery() as nursery:
nursery.start_soon(wait_and_tell, proc)
await wait_all_tasks_blocked()
assert noticed_exit is False
assert isinstance(noticed_exit, Event)
proc.terminate()
# without giving trio a chance to do so,
with assert_no_checkpoints():
# wait until the process has actually exited;
proc._proc.wait()
# force a call to poll (that closes the pidfd on linux)
proc.poll()
await wait_all_tasks_blocked()
assert noticed_exit, "child task wasn't woken after poll, DEADLOCK"
with move_on_after(5):
# Some platforms use threads to wait for exit, so it might take a bit
# for everything to notice
await noticed_exit.wait()
assert noticed_exit.is_set(), "child task wasn't woken after poll, DEADLOCK"

0 comments on commit 18a850c

Please sign in to comment.