Skip to content

Commit 0a45cc4

Browse files
authored
Fix ready promise and session send (#852)
1 parent 22ca9f0 commit 0a45cc4

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ jobs:
130130
pip check
131131
- name: Run the tests
132132
run: |
133-
pytest -vv jupyter_client || pytest -vv jupyter_client --lf
133+
pytest -vv -W default jupyter_client || pytest -vv -W default jupyter_client --lf
134134
135135
make_sdist:
136136
name: Make SDist

jupyter_client/manager.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,12 @@ def in_pending_state(method: F) -> F:
6565
@functools.wraps(method)
6666
async def wrapper(self, *args, **kwargs):
6767
# Create a future for the decorated method
68-
try:
69-
self._ready = Future()
70-
except RuntimeError:
71-
# No event loop running, use concurrent future
72-
self._ready = CFuture()
68+
if self._attempted_start:
69+
try:
70+
self._ready = Future()
71+
except RuntimeError:
72+
# No event loop running, use concurrent future
73+
self._ready = CFuture()
7374
try:
7475
# call wrapped method, await, and set the result or exception.
7576
out = await method(self, *args, **kwargs)
@@ -96,6 +97,7 @@ class KernelManager(ConnectionFileMixin):
9697
def __init__(self, *args, **kwargs):
9798
super().__init__(**kwargs)
9899
self._shutdown_status = _ShutdownStatus.Unset
100+
self._attempted_start = False
99101
# Create a place holder future.
100102
try:
101103
asyncio.get_running_loop()
@@ -382,6 +384,7 @@ async def _async_start_kernel(self, **kw: t.Any) -> None:
382384
keyword arguments that are passed down to build the kernel_cmd
383385
and launching the kernel (e.g. Popen kwargs).
384386
"""
387+
self._attempted_start = True
385388
kernel_cmd, kw = await ensure_async(self.pre_start_kernel(**kw))
386389

387390
# launch the kernel subprocess

jupyter_client/session.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from typing import Optional
3030
from typing import Union
3131

32-
import zmq
32+
import zmq.asyncio
3333
from traitlets import Any
3434
from traitlets import Bool
3535
from traitlets import CBytes
@@ -807,6 +807,10 @@ def send(
807807
# ZMQStreams and dummy sockets do not support tracking.
808808
track = False
809809

810+
if isinstance(stream, zmq.asyncio.Socket):
811+
assert stream is not None
812+
stream = zmq.Socket.shadow(stream.underlying)
813+
810814
if isinstance(msg_or_type, (Message, dict)):
811815
# We got a Message or message dict, not a msg_type so don't
812816
# build a new Message.

0 commit comments

Comments
 (0)