Skip to content

Commit

Permalink
Fix import on Windows, always use ProactorEventLoop
Browse files Browse the repository at this point in the history
  • Loading branch information
krassowski committed Jan 1, 2023
1 parent cb26fd5 commit 12bfbd4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
18 changes: 13 additions & 5 deletions python_packages/jupyter_lsp/jupyter_lsp/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from .connection import LspStreamReader, LspStreamWriter
from .schema import LANGUAGE_SERVER_SPEC
from .specs.utils import censored_spec
from .threaded_child_watcher import ThreadedChildWatcher
from .trait_types import Schema
from .types import SessionStatus
from .utils import get_unused_port
Expand Down Expand Up @@ -87,7 +86,8 @@ class LanguageServerSessionBase(

stop_timeout = Float(
5,
help="timeout in seconds after which a server process will be terminated forcefully",
help="timeout in seconds after which a server process will be terminated "
"forcefully",
).tag(config=True)
start_timeout = Float(
240,
Expand Down Expand Up @@ -132,9 +132,17 @@ def start(self):
self.main_loop = IOLoop.current()
self.started.clear()

policy = asyncio.DefaultEventLoopPolicy()
if sys.version_info < (3, 8) and sys.platform != "win32":
policy.set_child_watcher(ThreadedChildWatcher())
if sys.platform == "win32":
# harmonizes event loop across Python version on Windows.
# Python <3.8 did not use ProactorEventLoop as default.
# ProactorEventLoop supports subprocesses.
policy = asyncio.WindowsProactorEventLoopPolicy()
else:
policy = asyncio.DefaultEventLoopPolicy()
if sys.version_info < (3, 8):
from .threaded_child_watcher import ThreadedChildWatcher

policy.set_child_watcher(ThreadedChildWatcher())
self.thread = Thread(
target=anyio.run,
kwargs={"func": self.run, "backend_options": {"policy": policy}},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
agrees to be bound by the terms and conditions of this License
Agreement.
"""
# flake8: noqa
import itertools
import os
import threading
Expand Down

0 comments on commit 12bfbd4

Please sign in to comment.