Skip to content

Commit

Permalink
Remove some potential dead-code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Carreau committed Oct 17, 2024
1 parent 314cc49 commit 735a4fb
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 56 deletions.
34 changes: 2 additions & 32 deletions examples/embedding/inprocess_qtconsole.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,24 @@
"""An in-process qt console app."""
import os
import sys

import tornado
from IPython.lib import guisupport
from qtconsole.inprocess import QtInProcessKernelManager
from qtconsole.rich_ipython_widget import RichIPythonWidget

assert tornado.version_info >= (6, 1)


def print_process_id():
"""Print the process id."""
print("Process ID is:", os.getpid())


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 overridable
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)
and tornado.version_info < (6, 1)
):
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())


def main():
"""The main entry point."""
# Print the ID of the main process
print_process_id()

init_asyncio_patch()
app = guisupport.get_app_qt4()

# Create an in-process kernel
Expand Down
2 changes: 1 addition & 1 deletion ipykernel/kernelapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ def _init_asyncio_patch(self):
where asyncio.ProactorEventLoop supports add_reader and friends.
"""
if sys.platform.startswith("win") and sys.version_info >= (3, 8):
if sys.platform.startswith("win"):
import asyncio

try:
Expand Down
22 changes: 1 addition & 21 deletions tests/test_eventloop.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import time

import pytest
import tornado

from ipykernel.eventloops import (
enable_gui,
Expand All @@ -16,7 +15,7 @@
loop_tk,
)

from .utils import execute, flush_channels, start_new_kernel
from .utils import flush_channels, start_new_kernel

KC = KM = None

Expand Down Expand Up @@ -61,25 +60,6 @@ def _setup_env():
"""


@pytest.mark.skipif(tornado.version_info < (5,), reason="only relevant on tornado 5")
def test_asyncio_interrupt():
assert KM is not None
assert KC is not None
flush_channels(KC)
msg_id, content = execute("%gui asyncio", KC)
assert content["status"] == "ok", content

flush_channels(KC)
msg_id, content = execute(async_code, KC)
assert content["status"] == "ok", content

KM.interrupt_kernel()

flush_channels(KC)
msg_id, content = execute(async_code, KC)
assert content["status"] == "ok"


windows_skip = pytest.mark.skipif(os.name == "nt", reason="causing failures on windows")


Expand Down
4 changes: 2 additions & 2 deletions tests/test_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def test_sys_path_profile_dir():

@flaky(max_runs=3)
@pytest.mark.skipif(
sys.platform == "win32" or (sys.platform == "darwin" and sys.version_info >= (3, 8)),
sys.platform == "win32" or (sys.platform == "darwin"),
reason="subprocess prints fail on Windows and MacOS Python 3.8+",
)
def test_subprocess_print():
Expand Down Expand Up @@ -267,7 +267,7 @@ def test_subprocess_noprint():

@flaky(max_runs=3)
@pytest.mark.skipif(
sys.platform == "win32" or (sys.platform == "darwin" and sys.version_info >= (3, 8)),
(sys.platform == "win32") or (sys.platform == "darwin"),
reason="subprocess prints fail on Windows and MacOS Python 3.8+",
)
def test_subprocess_error():
Expand Down

0 comments on commit 735a4fb

Please sign in to comment.