Skip to content

Commit

Permalink
use ensure_event_loop
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 committed Jan 7, 2024
1 parent 8aa1d10 commit 46ff764
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
22 changes: 19 additions & 3 deletions jupyter_client/kernelapp.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
"""An application to launch a kernel by name in a local subprocess."""
import asyncio
import functools
import logging
import os
import signal
import typing as t
import uuid

from jupyter_core.application import JupyterAsyncApp, base_flags
from jupyter_core.paths import (
jupyter_runtime_dir,
)
from jupyter_core.utils import ensure_dir_exists
from traitlets import Unicode

from . import __version__
Expand All @@ -32,16 +37,27 @@ class KernelApp(JupyterAsyncApp):
config=True
)

# TODO: remove after jupyter_core 5.7.1
runtime_dir = Unicode()

def _runtime_dir_default(self) -> str:
rd = jupyter_runtime_dir()
ensure_dir_exists(rd, mode=0o700)
return rd

def _log_level_default(self) -> int:
return logging.INFO

# END TODO

async def initialize_async(self, argv: t.Union[str, t.Sequence[str], None] = None) -> None:
"""Initialize the application."""
super().initialize(argv)

cf_basename = "kernel-%s.json" % uuid.uuid4()
self.config.setdefault("KernelManager", {}).setdefault(
"connection_file", os.path.join(self.runtime_dir, cf_basename)
)
self.km = AsyncKernelManager(kernel_name=self.kernel_name, config=self.config)
await self._record_started()
self._record_started()
self._stopped_fut: asyncio.Future[int] = asyncio.Future()
self._running = None

Expand Down
4 changes: 2 additions & 2 deletions jupyter_client/threaded.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from .channels import HBChannel
from .client import KernelClient
from .session import Session
from .utils import get_event_loop
from .utils import ensure_event_loop

# Local imports
# import ZMQError in top-level namespace, to avoid ugly attribute-error messages
Expand Down Expand Up @@ -54,7 +54,7 @@ def __init__(

self.socket = socket
self.session = session
self.ioloop = loop or get_event_loop()
self.ioloop = loop or ensure_event_loop()

_is_alive = False

Expand Down

0 comments on commit 46ff764

Please sign in to comment.