Skip to content

Commit f5b819b

Browse files
committed
fix failure
1 parent 149ad9d commit f5b819b

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

qasync/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,10 @@ def _use_qeventloop(loop_factory):
824824
loop = QEventLoop(app)
825825
else:
826826
loop = loop_factory(app)
827-
old_loop = asyncio.get_event_loop()
827+
try:
828+
old_loop = asyncio.get_event_loop()
829+
except RuntimeError: # No current event loop
830+
old_loop = None
828831
asyncio.set_event_loop(loop)
829832
try:
830833
yield loop

tests/test_run.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import qasync
22
import asyncio
3+
from qasync import QApplication
34

45
def test_run_with_contextmanager(application):
56
async def coro():
67
event_loop = asyncio.get_event_loop()
78
assert type(event_loop).__name__ == "QSelectorEventLoop"
89
await asyncio.sleep(0)
910

10-
_ = application
1111
qasync.run(coro())
1212

13-
event_loop = asyncio.get_event_loop()
13+
try:
14+
event_loop = asyncio.get_event_loop()
15+
except:
16+
event_loop = None
1417
assert type(event_loop).__name__ != "QSelectorEventLoop"

0 commit comments

Comments
 (0)