From 2c920e3518f506602950abd1fdbd49c4a9e09c0d Mon Sep 17 00:00:00 2001 From: maximlt Date: Mon, 3 Oct 2022 19:25:02 +0200 Subject: [PATCH 1/2] set the event loop policy on Windows --- nbsmoke/__init__.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/nbsmoke/__init__.py b/nbsmoke/__init__.py index 83da5a4..e85aa2d 100644 --- a/nbsmoke/__init__.py +++ b/nbsmoke/__init__.py @@ -8,6 +8,7 @@ import os import io import contextlib +import sys import param @@ -91,6 +92,20 @@ def cwd(d): os.chdir(orig) +def fixup_windows_event_loop_policy() -> None: + if ( + sys.platform == 'win32' + and sys.version_info[:3] >= (3, 8, 0) + and tornado.version_info < (6, 1) + ): + import asyncio + if type(asyncio.get_event_loop_policy()) is asyncio.WindowsProactorEventLoopPolicy: + # WindowsProactorEventLoopPolicy is not compatible with tornado 6 + # fallback to the pre-3.8 default of WindowsSelectorEventLoopPolicy + asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) + + +fixup_windows_event_loop_policy() ################################################### From 05410ef80a96127eeb43f0d294c50e282f22f446 Mon Sep 17 00:00:00 2001 From: maximlt Date: Mon, 3 Oct 2022 19:33:14 +0200 Subject: [PATCH 2/2] check for tornado --- nbsmoke/__init__.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/nbsmoke/__init__.py b/nbsmoke/__init__.py index e85aa2d..d5313ab 100644 --- a/nbsmoke/__init__.py +++ b/nbsmoke/__init__.py @@ -93,6 +93,13 @@ def cwd(d): def fixup_windows_event_loop_policy() -> None: + try: + import tornado + except ImportError: + tornado = None + if not tornado: + return + # This part of the code comes from Bokeh's source code. if ( sys.platform == 'win32' and sys.version_info[:3] >= (3, 8, 0)