Skip to content

Commit

Permalink
Merge pull request #19 from psyplot/fix-win
Browse files Browse the repository at this point in the history
patch incompatibility between tornado and asyncio
  • Loading branch information
Chilipp committed Sep 17, 2020
2 parents f59bc04 + 7891de2 commit 6d3cb71
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions psyplot_gui/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,34 @@
logger = logging.getLogger(__name__)


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 IPythonControl(QTextEdit):
"""A modified control to show the help of objects in the help explorer"""

Expand Down Expand Up @@ -93,6 +121,12 @@ def __init__(self, main, *args, **kwargs):
:class:`qtconsole.rich_jupyter_widget.RichJupyterWidget`
"""
self._closed = False

# Create an in-process kernel
# >>> print_process_id()
# will print the same process ID as the main process
init_asyncio_patch()

kernel_manager = QtInProcessKernelManager()
# on windows, sys.stdout may be None when using pythonw.exe. Therefore
# we just us a StringIO for security
Expand Down

0 comments on commit 6d3cb71

Please sign in to comment.