Skip to content

Commit e8185df

Browse files
authored
Revert "Enable ProactorEventLoop on windows for ipykernel" (#1194)
1 parent d57bbf2 commit e8185df

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

ipykernel/kernelapp.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,43 @@ def configure_tornado_logger(self):
624624
handler.setFormatter(formatter)
625625
logger.addHandler(handler)
626626

627+
def _init_asyncio_patch(self):
628+
"""set default asyncio policy to be compatible with tornado
629+
630+
Tornado 6 (at least) is not compatible with the default
631+
asyncio implementation on Windows
632+
633+
Pick the older SelectorEventLoopPolicy on Windows
634+
if the known-incompatible default policy is in use.
635+
636+
Support for Proactor via a background thread is available in tornado 6.1,
637+
but it is still preferable to run the Selector in the main thread
638+
instead of the background.
639+
640+
do this as early as possible to make it a low priority and overridable
641+
642+
ref: https://github.com/tornadoweb/tornado/issues/2608
643+
644+
FIXME: if/when tornado supports the defaults in asyncio without threads,
645+
remove and bump tornado requirement for py38.
646+
Most likely, this will mean a new Python version
647+
where asyncio.ProactorEventLoop supports add_reader and friends.
648+
649+
"""
650+
if sys.platform.startswith("win") and sys.version_info >= (3, 8):
651+
import asyncio
652+
653+
try:
654+
from asyncio import WindowsProactorEventLoopPolicy, WindowsSelectorEventLoopPolicy
655+
except ImportError:
656+
pass
657+
# not affected
658+
else:
659+
if type(asyncio.get_event_loop_policy()) is WindowsProactorEventLoopPolicy:
660+
# WindowsProactorEventLoopPolicy is not compatible with tornado 6
661+
# fallback to the pre-3.8 default of Selector
662+
asyncio.set_event_loop_policy(WindowsSelectorEventLoopPolicy())
663+
627664
def init_pdb(self):
628665
"""Replace pdb with IPython's version that is interruptible.
629666
@@ -643,6 +680,7 @@ def init_pdb(self):
643680
@catch_config_error
644681
def initialize(self, argv=None):
645682
"""Initialize the application."""
683+
self._init_asyncio_patch()
646684
super().initialize(argv)
647685
if self.subapp is not None:
648686
return

0 commit comments

Comments
 (0)