Skip to content

Commit

Permalink
Workaround tornado+py38+windows compatibility issue (Same as ipython#456
Browse files Browse the repository at this point in the history
). Set eventloop policy to the old default while tornado is not compatible with the new one.
  • Loading branch information
ericpre committed Jan 26, 2020
1 parent dbaf7f7 commit 06967ee
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions ipykernel/ipkernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,25 @@ def _user_ns_changed(self, name, old, new):
_sys_raw_input = Any()
_sys_eval_input = Any()

def _init_asyncio_patch(self):
if sys.platform.startswith("win") and sys.version_info >= (3, 8):
import asyncio
try:
from asyncio import (
WindowsProactorEventLoopPolicy,
WindowsSelectorEventLoopPolicy,
)
except ImportError:
pass
# not affected
else:
if type(asyncio.get_event_loop_policy()) is WindowsProactorEventLoopPolicy:
# WindowsProactorEventLoopPolicy is not compatible with tornado 6
# fallback to the pre-3.8 default of Selector
asyncio.set_event_loop_policy(WindowsSelectorEventLoopPolicy())

def __init__(self, **kwargs):
self._init_asyncio_patch()
super(IPythonKernel, self).__init__(**kwargs)

# Initialize the InteractiveShell subclass
Expand Down

0 comments on commit 06967ee

Please sign in to comment.