Skip to content

Commit

Permalink
Fix ready promise and session send (#852)
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 authored Oct 11, 2022
1 parent 22ca9f0 commit 0a45cc4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ jobs:
pip check
- name: Run the tests
run: |
pytest -vv jupyter_client || pytest -vv jupyter_client --lf
pytest -vv -W default jupyter_client || pytest -vv -W default jupyter_client --lf
make_sdist:
name: Make SDist
Expand Down
13 changes: 8 additions & 5 deletions jupyter_client/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ def in_pending_state(method: F) -> F:
@functools.wraps(method)
async def wrapper(self, *args, **kwargs):
# Create a future for the decorated method
try:
self._ready = Future()
except RuntimeError:
# No event loop running, use concurrent future
self._ready = CFuture()
if self._attempted_start:
try:
self._ready = Future()
except RuntimeError:
# No event loop running, use concurrent future
self._ready = CFuture()
try:
# call wrapped method, await, and set the result or exception.
out = await method(self, *args, **kwargs)
Expand All @@ -96,6 +97,7 @@ class KernelManager(ConnectionFileMixin):
def __init__(self, *args, **kwargs):
super().__init__(**kwargs)
self._shutdown_status = _ShutdownStatus.Unset
self._attempted_start = False
# Create a place holder future.
try:
asyncio.get_running_loop()
Expand Down Expand Up @@ -382,6 +384,7 @@ async def _async_start_kernel(self, **kw: t.Any) -> None:
keyword arguments that are passed down to build the kernel_cmd
and launching the kernel (e.g. Popen kwargs).
"""
self._attempted_start = True
kernel_cmd, kw = await ensure_async(self.pre_start_kernel(**kw))

# launch the kernel subprocess
Expand Down
6 changes: 5 additions & 1 deletion jupyter_client/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from typing import Optional
from typing import Union

import zmq
import zmq.asyncio
from traitlets import Any
from traitlets import Bool
from traitlets import CBytes
Expand Down Expand Up @@ -807,6 +807,10 @@ def send(
# ZMQStreams and dummy sockets do not support tracking.
track = False

if isinstance(stream, zmq.asyncio.Socket):
assert stream is not None
stream = zmq.Socket.shadow(stream.underlying)

if isinstance(msg_or_type, (Message, dict)):
# We got a Message or message dict, not a msg_type so don't
# build a new Message.
Expand Down

0 comments on commit 0a45cc4

Please sign in to comment.