aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliott Sales de Andrade <quantum.analyst@gmail.com>2022-07-27 02:00:37 -0400
committerEli Schwartz <eschwartz93@gmail.com>2022-08-01 15:51:16 -0400
commit27626124d0bdd89f5f276f70a73b4713aa3aac3d (patch)
treef6ebcdcc772d871224af2fbe84fcd670cd0d030b
parentfa71c38688e422a446b41c7f52d12c05e49716a8 (diff)
downloadmeson-27626124d0bdd89f5f276f70a73b4713aa3aac3d.zip
meson-27626124d0bdd89f5f276f70a73b4713aa3aac3d.tar.gz
meson-27626124d0bdd89f5f276f70a73b4713aa3aac3d.tar.bz2
Inline try_wait_one using asyncio.wait_for
Although the former accepts multiple awaitables, it is only ever called with a single one, so just use `wait_for` instead. Additionally, the `try_wait_one` fails in Python 3.11, as `Process.wait()` returns a coroutine, and `asyncio.wait` only accepts tasks, so it errors out.
-rw-r--r--mesonbuild/mtest.py15
1 files changed, 7 insertions, 8 deletions
diff --git a/mesonbuild/mtest.py b/mesonbuild/mtest.py
index d733ce8..80ffe5d 100644
--- a/mesonbuild/mtest.py
+++ b/mesonbuild/mtest.py
@@ -16,6 +16,7 @@
from pathlib import Path
from collections import deque
+from contextlib import suppress
from copy import deepcopy
import argparse
import asyncio
@@ -1161,11 +1162,6 @@ def check_testdata(objs: T.List[TestSerialisation]) -> T.List[TestSerialisation]
# Custom waiting primitives for asyncio
-async def try_wait_one(*awaitables: T.Any, timeout: T.Optional[T.Union[int, float]]) -> None:
- """Wait for completion of one of the given futures, ignoring timeouts."""
- await asyncio.wait(awaitables,
- timeout=timeout, return_when=asyncio.FIRST_COMPLETED)
-
async def queue_iter(q: 'asyncio.Queue[T.Optional[str]]') -> T.AsyncIterator[str]:
while True:
item = await q.get()
@@ -1273,13 +1269,15 @@ class TestSubprocess:
# Make sure the termination signal actually kills the process
# group, otherwise retry with a SIGKILL.
- await try_wait_one(p.wait(), timeout=0.5)
+ with suppress(TimeoutError):
+ await asyncio.wait_for(p.wait(), timeout=0.5)
if p.returncode is not None:
return None
os.killpg(p.pid, signal.SIGKILL)
- await try_wait_one(p.wait(), timeout=1)
+ with suppress(TimeoutError):
+ await asyncio.wait_for(p.wait(), timeout=1)
if p.returncode is not None:
return None
@@ -1287,7 +1285,8 @@ class TestSubprocess:
# Try to kill it one last time with a direct call.
# If the process has spawned children, they will remain around.
p.kill()
- await try_wait_one(p.wait(), timeout=1)
+ with suppress(TimeoutError):
+ await asyncio.wait_for(p.wait(), timeout=1)
if p.returncode is not None:
return None
return 'Test process could not be killed.'