From 25e09ab52b87e998ef098bcf747d1df5a8c65560 Mon Sep 17 00:00:00 2001 From: Eric Prestat Date: Wed, 29 Jan 2020 12:50:42 +0000 Subject: [PATCH] Fix the consolewidget on windows with python 3.8, see https://github.com/ipython/ipykernel/pull/480. --- hyperspyui/widgets/consolewidget.py | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/hyperspyui/widgets/consolewidget.py b/hyperspyui/widgets/consolewidget.py index c5e25c91..feb7bd54 100644 --- a/hyperspyui/widgets/consolewidget.py +++ b/hyperspyui/widgets/consolewidget.py @@ -20,6 +20,7 @@ @author: Vidar Tonaas Fauske """ +import sys try: from qtconsole.rich_jupyter_widget import RichJupyterWidget @@ -31,11 +32,42 @@ from IPython.lib import guisupport +def _init_asyncio_patch(): + """set default asyncio policy to be compatible with tornado + Tornado 6 (at least) is not compatible with the default + asyncio implementation on Windows + + Pick the older SelectorEventLoopPolicy on Windows + if the known-incompatible default policy is in use. + do this as early as possible to make it a low priority and overrideable + + ref: https://github.com/tornadoweb/tornado/issues/2608 + FIXME: if/when tornado supports the defaults in asyncio, + remove and bump tornado requirement for py38 + """ + 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()) + + class ConsoleWidget(RichJupyterWidget): def __init__(self, *args, **kwargs): super(ConsoleWidget, self).__init__(*args, **kwargs) + _init_asyncio_patch() # Create an in-process kernel app = guisupport.get_app_qt4() kernel_manager = QtInProcessKernelManager()