Skip to content

Commit 29ec936

Browse files
committed
workaround tornado py38 compatibility issue
by setting the pre-3.8 eventloop policy as default
1 parent 9640e1f commit 29ec936

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

notebook/notebookapp.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,8 +1707,42 @@ def init_shutdown_no_activity(self):
17071707
pc = ioloop.PeriodicCallback(self.shutdown_no_activity, 60000)
17081708
pc.start()
17091709

1710+
def _init_asyncio_patch(self):
1711+
"""set default asyncio policy to be compatible with tornado
1712+
1713+
Tornado 6 (at least) is not compatible with the default
1714+
asyncio implementation on Windows
1715+
1716+
Pick the older SelectorEventLoopPolicy on Windows
1717+
if the known-incompatible default policy is in use.
1718+
1719+
do this as early as possible to make it a low priority and overrideable
1720+
1721+
ref: https://github.com/tornadoweb/tornado/issues/2608
1722+
1723+
FIXME: if/when tornado supports the defaults in asyncio,
1724+
remove and bump tornado requirement for py38
1725+
"""
1726+
if sys.platform.startswith("win") and sys.version_info >= (3, 8):
1727+
import asyncio
1728+
try:
1729+
from asyncio import (
1730+
WindowsProactorEventLoopPolicy,
1731+
WindowsSelectorEventLoopPolicy,
1732+
)
1733+
except ImportError:
1734+
pass
1735+
# not affected
1736+
else:
1737+
if type(asyncio.get_event_loop_policy()) is WindowsProactorEventLoopPolicy:
1738+
# WindowsProactorEventLoopPolicy is not compatible with tornado 6
1739+
# fallback to the pre-3.8 default of Selector
1740+
asyncio.set_event_loop_policy(WindowsSelectorEventLoopPolicy())
1741+
17101742
@catch_config_error
17111743
def initialize(self, argv=None):
1744+
self._init_asyncio_patch()
1745+
17121746
super(NotebookApp, self).initialize(argv)
17131747
self.init_logging()
17141748
if self._dispatching:

0 commit comments

Comments
 (0)