Skip to content

Commit 649561e

Browse files
committed
Make run_sync compatible with python 3.10.9
Fix jupyter#901
1 parent edde6e0 commit 649561e

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

jupyter_client/utils.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,25 @@
66
import asyncio
77
import inspect
88
import os
9+
import sys
910

1011

1112
def run_sync(coro):
1213
def wrapped(*args, **kwargs):
1314
try:
1415
loop = asyncio.get_running_loop()
1516
except RuntimeError:
16-
# Workaround for bugs.python.org/issue39529.
17-
try:
18-
loop = asyncio.get_event_loop_policy().get_event_loop()
19-
except RuntimeError:
17+
# In python 3.10.9 this workaround breaks some tests
18+
# test_client.TestKernelClient
19+
# https://docs.python.org/3.10/whatsnew/changelog.html#id3
20+
if sys.version_info <= (3, 10, 8):
21+
# Workaround for bugs.python.org/issue39529.
22+
try:
23+
loop = asyncio.get_event_loop_policy().get_event_loop()
24+
except RuntimeError:
25+
loop = asyncio.new_event_loop()
26+
asyncio.set_event_loop(loop)
27+
else:
2028
loop = asyncio.new_event_loop()
2129
asyncio.set_event_loop(loop)
2230
import nest_asyncio # type: ignore

0 commit comments

Comments
 (0)