@@ -1707,8 +1707,42 @@ def init_shutdown_no_activity(self):
1707
1707
pc = ioloop .PeriodicCallback (self .shutdown_no_activity , 60000 )
1708
1708
pc .start ()
1709
1709
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
+
1710
1742
@catch_config_error
1711
1743
def initialize (self , argv = None ):
1744
+ self ._init_asyncio_patch ()
1745
+
1712
1746
super (NotebookApp , self ).initialize (argv )
1713
1747
self .init_logging ()
1714
1748
if self ._dispatching :
0 commit comments