Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jupyter/jupyter_client
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v7.3.4
Choose a base ref
...
head repository: jupyter/jupyter_client
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: bc5ded5439ca55bd6740885eb3a44ca6bc3e2243
Choose a head ref
Loading
Showing with 40 additions and 29 deletions.
  1. +0 −1 .github/workflows/downstream.yml
  2. +10 −14 .pre-commit-config.yaml
  3. +16 −0 docs/api/client.rst
  4. +7 −4 jupyter_client/client.py
  5. +6 −9 jupyter_client/ioloop/restarter.py
  6. +1 −1 pyproject.toml
1 change: 0 additions & 1 deletion .github/workflows/downstream.yml
Original file line number Diff line number Diff line change
@@ -76,7 +76,6 @@ jobs:
git clone https://github.com/jupyter/jupyter_kernel_test.git
cd jupyter_kernel_test
conda env update --name jupyter_kernel_test --file environment.yml
conda install -c conda-forge xeus-cling
pip install -e ".[test]"
python -m unittest -v
24 changes: 10 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
rev: v4.3.0
hooks:
- id: end-of-file-fixer
- id: check-case-conflict
@@ -16,42 +16,38 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/asottile/reorder_python_imports
rev: v3.1.0
rev: v3.8.2
hooks:
- id: reorder-python-imports

- repo: https://github.com/psf/black
rev: 22.3.0
rev: 22.6.0
hooks:
- id: black
args: ["--line-length", "100"]

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.6.2
rev: v3.0.0-alpha.0
hooks:
- id: prettier

- repo: https://github.com/PyCQA/doc8
rev: 0.11.2
rev: v1.0.0
hooks:
- id: doc8
args: [--max-line-length=200]
stages: [manual]

- repo: https://github.com/pycqa/flake8
rev: 4.0.1
rev: 5.0.4
hooks:
- id: flake8
additional_dependencies:
[
"flake8-bugbear==20.1.4",
"flake8-logging-format==0.6.0",
"flake8-implicit-str-concat==0.2.0",
]
["flake8-bugbear==22.6.22", "flake8-implicit-str-concat==0.2.0"]
stages: [manual]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.960
rev: v0.971
hooks:
- id: mypy
exclude: jupyter_client/tests
@@ -60,13 +56,13 @@ repos:
stages: [manual]

- repo: https://github.com/PyCQA/doc8
rev: 0.11.2
rev: v1.0.0
hooks:
- id: doc8
args: [--max-line-length=100]

- repo: https://github.com/sirosen/check-jsonschema
rev: 0.16.0
rev: 0.17.1
hooks:
- id: check-jsonschema
name: "Check GitHub Workflows"
16 changes: 16 additions & 0 deletions docs/api/client.rst
Original file line number Diff line number Diff line change
@@ -35,3 +35,19 @@ client - communicating with kernels
.. autoclass:: BlockingKernelClient

.. automethod:: execute_interactive

.. automethod:: get_shell_msg

.. automethod:: get_iopub_msg

.. automethod:: get_stdin_msg

.. automethod:: get_control_msg

.. automethod:: wait_for_ready

.. automethod:: is_alive

.. autoclass:: AsyncKernelClient

:class:`AsyncKernelClient` is identical to :class:`BlockingKernelClient` but the methods described above are async.
11 changes: 7 additions & 4 deletions jupyter_client/client.py
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import asyncio
import inspect
import sys
import time
import typing as t
@@ -232,7 +233,7 @@ async def _async_recv_reply(
continue
return reply

def _stdin_hook_default(self, msg: t.Dict[str, t.Any]) -> None:
async def _stdin_hook_default(self, msg: t.Dict[str, t.Any]) -> None:
"""Handle an input request"""
content = msg["content"]
if content.get("password", False):
@@ -251,7 +252,7 @@ def _stdin_hook_default(self, msg: t.Dict[str, t.Any]) -> None:

# only send stdin reply if there *was not* another request
# or execution finished while we were reading.
if not (self.stdin_channel.msg_ready() or self.shell_channel.msg_ready()):
if not (await self.stdin_channel.msg_ready() or await self.shell_channel.msg_ready()):
self.input(raw_data)

def _output_hook_default(self, msg: t.Dict[str, t.Any]) -> None:
@@ -469,7 +470,7 @@ async def _async_execute_interactive(
If not specified, output will be redisplayed.
stdin_hook: callable(msg)
Function to be called with stdin_request messages.
Function or awaitable to be called with stdin_request messages.
If not specified, input/getpass will be called.
Returns
@@ -536,7 +537,9 @@ async def _async_execute_interactive(
raise TimeoutError("Timeout waiting for output")
if stdin_socket in events:
req = await self.stdin_channel.get_msg(timeout=0)
stdin_hook(req)
res = stdin_hook(req)
if inspect.isawaitable(res):
await res
continue
if iopub_socket not in events:
continue
15 changes: 6 additions & 9 deletions jupyter_client/ioloop/restarter.py
Original file line number Diff line number Diff line change
@@ -5,15 +5,12 @@
"""
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import asyncio
import time
import warnings

from traitlets import Instance
from zmq.eventloop import ioloop

from jupyter_client.restarter import KernelRestarter
from jupyter_client.utils import run_sync


class IOLoopKernelRestarter(KernelRestarter):
@@ -27,19 +24,19 @@ def _loop_default(self):
DeprecationWarning,
stacklevel=4,
)
from zmq.eventloop import ioloop

return ioloop.IOLoop.current()

_pcallback = None

def start(self):
"""Start the polling of the kernel."""
if self._pcallback is None:
if asyncio.iscoroutinefunction(self.poll):
cb = run_sync(self.poll)
else:
cb = self.poll
self._pcallback = ioloop.PeriodicCallback(
cb,
from tornado.ioloop import PeriodicCallback

self._pcallback = PeriodicCallback(
self.poll,
1000 * self.time_to_dead,
)
self._pcallback.start()
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ dependencies = [
"nest-asyncio>=1.5.4",
"python-dateutil>=2.8.2",
"pyzmq>=23.0",
"tornado>=6.0",
"tornado>=6.2",
"traitlets",
]