Skip to content

Commit

Permalink
Make run_sync compatible with python 3.10.9
Browse files Browse the repository at this point in the history
  • Loading branch information
danigm committed Dec 15, 2022
1 parent edde6e0 commit 0bd859c
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions jupyter_client/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,25 @@
import asyncio
import inspect
import os
import sys


def run_sync(coro):
def wrapped(*args, **kwargs):
try:
loop = asyncio.get_running_loop()
except RuntimeError:
# Workaround for bugs.python.org/issue39529.
try:
loop = asyncio.get_event_loop_policy().get_event_loop()
except RuntimeError:
# In python 3.10.9 this workaround breaks some tests
# test_client.TestKernelClient
# https://github.com/python/cpython/issues/83710
if sys.version_info <= (3, 10, 8):
# Workaround for bugs.python.org/issue39529.
try:
loop = asyncio.get_event_loop_policy().get_event_loop()
except RuntimeError:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
else:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
import nest_asyncio # type: ignore
Expand Down

0 comments on commit 0bd859c

Please sign in to comment.