Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make run_sync compatible with python 3.10.9 #902

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ jobs:
python-version: "3.9"
- os: ubuntu-latest
python-version: "pypy-3.8"
- os: ubuntu-latest
python-version: "3.10.9"
- os: ubuntu-latest
python-version: "3.11"
- os: macos-latest
Expand Down
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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this changes the behavior. In the else, should we try to use get_running_loop before creating a new event loop?

loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
import nest_asyncio # type: ignore
Expand Down