Skip to content

Subshells implemented using tornado event loops on 6.x branch #1396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: 6.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@ jobs:
timeout-minutes: 15
if: ${{ !startsWith( matrix.python-version, 'pypy' ) && !startsWith(matrix.os, 'windows') }}
run: |
hatch run cov:test --cov-fail-under 50 || hatch run test:test --lf
hatch run cov:test --cov-fail-under 50

- name: Run the tests on pypy
timeout-minutes: 15
if: ${{ startsWith( matrix.python-version, 'pypy' ) }}
run: |
hatch run test:nowarn || hatch run test:nowarn --lf
hatch run test:nowarn

- name: Run the tests on Windows
timeout-minutes: 15
if: ${{ startsWith(matrix.os, 'windows') }}
run: |
hatch run cov:nowarn || hatch run test:nowarn --lf
hatch run cov:nowarn

- name: Check Launcher
run: |
Expand Down Expand Up @@ -144,7 +144,7 @@ jobs:

- name: Run the tests
timeout-minutes: 15
run: pytest -W default -vv || pytest --vv -W default --lf
run: pytest -W default -vv

test_miniumum_versions:
name: Test Minimum Versions
Expand All @@ -164,7 +164,7 @@ jobs:

- name: Run the unit tests
run: |
hatch -v run test:nowarn || hatch run test:nowarn --lf
hatch -v run test:nowarn

test_prereleases:
name: Test Prereleases
Expand All @@ -179,7 +179,7 @@ jobs:
dependency_type: pre
- name: Run the tests
run: |
hatch run test:nowarn || hatch run test:nowarn --lf
hatch run test:nowarn

make_sdist:
name: Make SDist
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/downstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ jobs:
shell: bash -l {0}
run: |
cd ${GITHUB_WORKSPACE}/..
git clone https://github.com/jupyter/qtconsole.git
git clone https://github.com/spyder-ide/qtconsole.git
cd qtconsole
${pythonLocation}/bin/python -m pip install -e ".[test]"
${pythonLocation}/bin/python -m pip install pyqt5
Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 2
build:
os: ubuntu-22.04
tools:
python: "3.11"
python: "3.13"

sphinx:
configuration: docs/conf.py
Expand Down
6 changes: 3 additions & 3 deletions docs/api/ipykernel.comm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ Submodules

.. automodule:: ipykernel.comm.comm
:members:
:show-inheritance:
:undoc-members:
:show-inheritance:


.. automodule:: ipykernel.comm.manager
:members:
:show-inheritance:
:undoc-members:
:show-inheritance:

Module contents
---------------

.. automodule:: ipykernel.comm
:members:
:show-inheritance:
:undoc-members:
:show-inheritance:
16 changes: 8 additions & 8 deletions docs/api/ipykernel.inprocess.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,49 @@ Submodules

.. automodule:: ipykernel.inprocess.blocking
:members:
:show-inheritance:
:undoc-members:
:show-inheritance:


.. automodule:: ipykernel.inprocess.channels
:members:
:show-inheritance:
:undoc-members:
:show-inheritance:


.. automodule:: ipykernel.inprocess.client
:members:
:show-inheritance:
:undoc-members:
:show-inheritance:


.. automodule:: ipykernel.inprocess.constants
:members:
:show-inheritance:
:undoc-members:
:show-inheritance:


.. automodule:: ipykernel.inprocess.ipkernel
:members:
:show-inheritance:
:undoc-members:
:show-inheritance:


.. automodule:: ipykernel.inprocess.manager
:members:
:show-inheritance:
:undoc-members:
:show-inheritance:


.. automodule:: ipykernel.inprocess.socket
:members:
:show-inheritance:
:undoc-members:
:show-inheritance:

Module contents
---------------

.. automodule:: ipykernel.inprocess
:members:
:show-inheritance:
:undoc-members:
:show-inheritance:
64 changes: 47 additions & 17 deletions docs/api/ipykernel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,115 +16,145 @@ Submodules

.. automodule:: ipykernel.compiler
:members:
:show-inheritance:
:undoc-members:
:show-inheritance:


.. automodule:: ipykernel.connect
:members:
:show-inheritance:
:undoc-members:
:show-inheritance:


.. automodule:: ipykernel.control
:members:
:show-inheritance:
:undoc-members:
:show-inheritance:


.. automodule:: ipykernel.debugger
:members:
:show-inheritance:
:undoc-members:
:show-inheritance:


.. automodule:: ipykernel.displayhook
:members:
:show-inheritance:
:undoc-members:
:show-inheritance:


.. automodule:: ipykernel.embed
:members:
:show-inheritance:
:undoc-members:
:show-inheritance:


.. automodule:: ipykernel.eventloops
:members:
:show-inheritance:
:undoc-members:
:show-inheritance:


.. automodule:: ipykernel.heartbeat
:members:
:show-inheritance:
:undoc-members:
:show-inheritance:


.. automodule:: ipykernel.iostream
:members:
:show-inheritance:
:undoc-members:
:show-inheritance:


.. automodule:: ipykernel.ipkernel
:members:
:show-inheritance:
:undoc-members:
:show-inheritance:


.. automodule:: ipykernel.jsonutil
:members:
:show-inheritance:
:undoc-members:
:show-inheritance:


.. automodule:: ipykernel.kernelapp
:members:
:show-inheritance:
:undoc-members:
:show-inheritance:


.. automodule:: ipykernel.kernelbase
:members:
:show-inheritance:
:undoc-members:
:show-inheritance:


.. automodule:: ipykernel.kernelspec
:members:
:show-inheritance:
:undoc-members:
:show-inheritance:


.. automodule:: ipykernel.log
:members:
:show-inheritance:
:undoc-members:
:show-inheritance:


.. automodule:: ipykernel.parentpoller
:members:
:undoc-members:
:show-inheritance:


.. automodule:: ipykernel.shellchannel
:members:
:undoc-members:
:show-inheritance:


.. automodule:: ipykernel.subshell
:members:
:undoc-members:
:show-inheritance:


.. automodule:: ipykernel.subshell_manager
:members:
:undoc-members:
:show-inheritance:


.. automodule:: ipykernel.thread
:members:
:undoc-members:
:show-inheritance:


.. automodule:: ipykernel.trio_runner
:members:
:undoc-members:
:show-inheritance:


.. automodule:: ipykernel.utils
:members:
:undoc-members:
:show-inheritance:


.. automodule:: ipykernel.zmqshell
:members:
:show-inheritance:
:undoc-members:
:show-inheritance:

Module contents
---------------

.. automodule:: ipykernel
:members:
:show-inheritance:
:undoc-members:
:show-inheritance:
27 changes: 3 additions & 24 deletions ipykernel/control.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,11 @@
"""A thread for a control channel."""
from threading import Thread

from tornado.ioloop import IOLoop
from .thread import CONTROL_THREAD_NAME, BaseThread

CONTROL_THREAD_NAME = "Control"


class ControlThread(Thread):
class ControlThread(BaseThread):
"""A thread for a control channel."""

def __init__(self, **kwargs):
"""Initialize the thread."""
Thread.__init__(self, name=CONTROL_THREAD_NAME, **kwargs)
self.io_loop = IOLoop(make_current=False)
self.pydev_do_not_trace = True
self.is_pydev_daemon_thread = True

def run(self):
"""Run the thread."""
self.name = CONTROL_THREAD_NAME
try:
self.io_loop.start()
finally:
self.io_loop.close()

def stop(self):
"""Stop the thread.

This method is threadsafe.
"""
self.io_loop.add_callback(self.io_loop.stop)
super().__init__(name=CONTROL_THREAD_NAME, **kwargs)
12 changes: 11 additions & 1 deletion ipykernel/ipkernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,11 @@ def set_sigint_result():
# restore the previous sigint handler
signal.signal(signal.SIGINT, save_sigint)

@contextmanager
def _dummy_context_manager(self, *args):
# Signals only work in main thread, so cannot use _cancel_on_sigint in subshells.
yield

async def execute_request(self, stream, ident, parent):
"""Override for cell output - cell reconciliation."""
parent_header = extract_header(parent)
Expand Down Expand Up @@ -439,7 +444,12 @@ async def run_cell(*args, **kwargs):

coro_future = asyncio.ensure_future(coro)

with self._cancel_on_sigint(coro_future):
cm = (
self._cancel_on_sigint
if threading.current_thread() == threading.main_thread()
else self._dummy_context_manager
)
with cm(coro_future): # type:ignore[operator]
res = None
try:
res = await coro_future
Expand Down
Loading
Loading