Skip to content

Commit 901d112

Browse files
committed
Use asyncio.run on windows
1 parent a4406bc commit 901d112

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

plugboard/_zmq/zmq_proxy.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@
77
import typing as _t
88

99
from pydantic import BaseModel, Field, ValidationError
10-
import uvloop
1110
import zmq
1211
import zmq.asyncio
1312

1413

14+
try:
15+
from uvloop import run as _asyncio_run
16+
except ImportError: # pragma: no cover
17+
from asyncio import run as _asyncio_run
18+
1519
zmq_sockopts_t: _t.TypeAlias = list[tuple[int, int | bytes | str]]
1620
ZMQ_ADDR: str = r"tcp://127.0.0.1"
1721

@@ -163,7 +167,7 @@ def _start_proxy(
163167
def _run_process(self) -> None:
164168
"""Entry point for the child process."""
165169
try:
166-
uvloop.run(self._run())
170+
_asyncio_run(self._run())
167171
finally: # pragma: no cover
168172
self._close()
169173

plugboard/utils/async_utils.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
from concurrent.futures import ThreadPoolExecutor
55
import typing as _t
66

7-
import uvloop
7+
8+
try:
9+
from uvloop import run as _asyncio_run
10+
except ImportError: # pragma: no cover
11+
from asyncio import run as _asyncio_run
812

913

1014
async def gather_except(*coros: _t.Coroutine) -> list[_t.Any]:
@@ -18,7 +22,7 @@ async def gather_except(*coros: _t.Coroutine) -> list[_t.Any]:
1822

1923
def _run_coro_in_thread(coro: _t.Coroutine, timeout: _t.Optional[float] = None) -> _t.Any:
2024
def _target() -> _t.Any:
21-
return uvloop.run(coro)
25+
return _asyncio_run(coro)
2226

2327
with ThreadPoolExecutor() as pool:
2428
future = pool.submit(_target)
@@ -36,7 +40,7 @@ def run_coro_sync(coro: _t.Coroutine, timeout: _t.Optional[float] = None) -> _t.
3640
loop = asyncio.get_running_loop()
3741
except RuntimeError: # pragma: no cover
3842
# No loop running in current thread
39-
return uvloop.run(coro)
43+
return _asyncio_run(coro)
4044

4145
if loop.is_running():
4246
# Run coroutine in new thread with dedicated event loop.

0 commit comments

Comments
 (0)