Skip to content

Commit d9d426b

Browse files
committed
2025-01-07T19:58:50Z
1 parent 566b456 commit d9d426b

File tree

6 files changed

+10
-29
lines changed

6 files changed

+10
-29
lines changed

omlish/asyncs/asyncio/all.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# ruff: noqa: I001
22
from .asyncio import ( # noqa
33
asyncio_once,
4-
get_real_current_loop,
54
drain_tasks,
65
draining_asyncio_tasks,
76
)

omlish/asyncs/asyncio/asyncio.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,17 @@ async def inner(*args, **kwargs):
2020
return ta.cast(CallableT, inner)
2121

2222

23-
def get_real_current_loop() -> asyncio.AbstractEventLoop | None:
24-
return asyncio.get_event_loop_policy()._local._loop # type: ignore # noqa
25-
26-
2723
def drain_tasks(loop=None):
2824
if loop is None:
29-
loop = get_real_current_loop()
25+
loop = asyncio.get_running_loop()
3026

3127
while loop._ready or loop._scheduled: # noqa
3228
loop._run_once() # noqa
3329

3430

3531
@contextlib.contextmanager
3632
def draining_asyncio_tasks() -> ta.Iterator[None]:
37-
loop = get_real_current_loop()
33+
loop = asyncio.get_running_loop()
3834
try:
3935
yield
4036
finally:

omlish/asyncs/bridge.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class BridgeAwaitRequiredError(Exception):
8686
pass
8787

8888

89-
class MissingBridgeGreenletError(Exception):
89+
class MissingBridgeThreadletError(Exception):
9090
pass
9191

9292

@@ -224,7 +224,7 @@ def s_to_a_await(awaitable: ta.Awaitable[T]) -> T:
224224

225225
if not getattr(g.underlying, _BRIDGE_THREADLET_ATTR, False):
226226
_safe_cancel_awaitable(awaitable)
227-
raise MissingBridgeGreenletError
227+
raise MissingBridgeThreadletError
228228

229229
return check.not_none(g.parent).switch(awaitable)
230230

omlish/asyncs/tests/test_flavors.py

-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import trio
88

99
from ... import lang
10-
from ...diag import pydevd as pdu
1110
from ...testing import pytest as ptu
1211
from .. import flavors
1312

@@ -21,14 +20,6 @@
2120
##
2221

2322

24-
@pytest.fixture(autouse=True)
25-
def _patch_for_trio_asyncio_fixture():
26-
pdu.patch_for_trio_asyncio()
27-
28-
29-
##
30-
31-
3223
@flavors.mark_anyio
3324
async def _anyio_func(call_asyncio, call_trio):
3425
await anyio.sleep(0)

omlish/asyncs/tests/test_greenlet.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def f():
3636

3737

3838
@ptu.skip.if_cant_import('greenlet')
39-
def test_bridge(event_loop):
39+
def test_bridge():
4040
import greenlet
4141

4242
l = []
@@ -69,4 +69,5 @@ async def main():
6969
)
7070
assert rs == [4, 4]
7171

72-
event_loop.run_until_complete(main()) # noqa
72+
with asyncio.Runner() as runner:
73+
runner.get_loop().run_until_complete(main()) # noqa

omlish/asyncs/tests/test_trio_asyncio.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
import trio
1616

1717
from ... import lang
18-
from ...diag import pydevd as pdu
1918
from ...testing import pytest as ptu
20-
from ..asyncio import all as asu
2119

2220

2321
if ta.TYPE_CHECKING:
@@ -26,11 +24,6 @@
2624
trai = lang.proxy_import('trio_asyncio')
2725

2826

29-
@pytest.fixture(autouse=True)
30-
def _patch_for_trio_asyncio_fixture():
31-
pdu.patch_for_trio_asyncio()
32-
33-
3427
@ptu.skip.if_cant_import('trio_asyncio')
3528
def test_hybrid():
3629
async def hybrid():
@@ -179,7 +172,7 @@ async def test_all_asyncs(__async_backend): # noqa
179172
match __async_backend:
180173
case 'asyncio':
181174
assert backend == 'asyncio'
182-
assert asu.get_real_current_loop() is not None
175+
assert asyncio.get_running_loop() is not None
183176
assert trai.current_loop.get() is None
184177
assert not isinstance(asyncio.get_running_loop(), trai.TrioEventLoop)
185178

@@ -189,7 +182,8 @@ async def test_all_asyncs(__async_backend): # noqa
189182

190183
case 'trio':
191184
assert backend == 'trio'
192-
assert asu.get_real_current_loop() is None
185+
with pytest.raises(RuntimeError):
186+
assert asyncio.get_running_loop()
193187
assert trai.current_loop.get() is None
194188

195189
with pytest.raises(RuntimeError):

0 commit comments

Comments
 (0)