conkernelclient 0.0.9__tar.gz → 0.0.11__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: conkernelclient
3
- Version: 0.0.9
3
+ Version: 0.0.11
4
4
  Summary: Concurrent-safe Jupyter KernelClient
5
5
  Author-email: Jeremy Howard <github@jhoward.fastmail.fm>
6
6
  License: Apache-2.0
@@ -0,0 +1,2 @@
1
+ __version__ = "0.0.11"
2
+ from .core import *
@@ -21,4 +21,5 @@ d = { 'settings': { 'branch': 'main',
21
21
  'conkernelclient.core.ConKernelClient.stop_channels': ( 'core.html#conkernelclient.stop_channels',
22
22
  'conkernelclient/core.py'),
23
23
  'conkernelclient.core.ConKernelManager': ('core.html#conkernelmanager', 'conkernelclient/core.py'),
24
+ 'conkernelclient.core.DeadKernelError': ('core.html#deadkernelerror', 'conkernelclient/core.py'),
24
25
  'conkernelclient.core._send': ('core.html#_send', 'conkernelclient/core.py')}}}
@@ -1,9 +1,11 @@
1
- """Concurrent-safe Jupyter KernelClient"""
1
+ """Concurrent-safe Jupyter KernelClient
2
+
3
+ Docs: https://AnswerDotAI.github.io/conkernelclientcore.html.md"""
2
4
 
3
5
  # AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/00_core.ipynb.
4
6
 
5
7
  # %% auto #0
6
- __all__ = ['ConKernelClient', 'ConKernelManager']
8
+ __all__ = ['DeadKernelError', 'ConKernelClient', 'ConKernelManager']
7
9
 
8
10
  # %% ../nbs/00_core.ipynb #d3b521c0
9
11
  from queue import Empty
@@ -20,6 +22,9 @@ import asyncio, zmq.asyncio, time, logging
20
22
  # %% ../nbs/00_core.ipynb #737a0fc1
21
23
  _log = logging.getLogger(__name__)
22
24
 
25
+ # %% ../nbs/00_core.ipynb #a093006c
26
+ class DeadKernelError(Exception): pass
27
+
23
28
  # %% ../nbs/00_core.ipynb #374b75d0
24
29
  if not hasattr(Session, '_orig_send'): Session._orig_send = Session.send
25
30
 
@@ -61,6 +66,7 @@ class ConKernelClient(AsyncKernelClient):
61
66
  while True:
62
67
  try: reply = await self.get_shell_msg(timeout=None)
63
68
  except Exception as e:
69
+ if isinstance(e, (AssertionError, OSError, ZMQError)): e = DeadKernelError(f"Kernel socket closed: {e}")
64
70
  self._fail_pending(e)
65
71
  _log.warning(f"_reader died, pending={list(self._pending)}: {e}")
66
72
  break
@@ -70,7 +76,6 @@ class ConKernelClient(AsyncKernelClient):
70
76
  q, soe = pend
71
77
  try: q.put_nowait(reply)
72
78
  except asyncio.QueueFull: pass
73
- else: _log.warning(f"Orphan reply for {reply['parent_header'].get('msg_id')}, pending={list(self._pending)}")
74
79
  cts = reply.get("content", {})
75
80
  if cts.get("status") in ("error", "aborted") and pend and soe:
76
81
  exc = RuntimeError(f"Kernel error aborted: {cts.get('ename')}: {cts.get('evalue')}")
@@ -111,13 +116,15 @@ class ConKernelClient(AsyncKernelClient):
111
116
  if subsh_id is not None: msg["header"]["subshell_id"] = subsh_id
112
117
  msg_id = msg["header"]["msg_id"]
113
118
  if reply: self._pending[msg_id] = (asyncio.Queue(maxsize=1), stop_on_error)
114
- self.shell_channel.send(msg)
119
+ try: self.shell_channel.send(msg)
120
+ except (AssertionError, OSError, ZMQError) as e: raise DeadKernelError(f"Kernel socket closed: {e}") from e
115
121
  if not reply: return msg_id
116
122
  return self._async_recv_reply(msg_id, timeout=timeout)
117
123
 
118
124
  async def stdin_send(self, msg:dict):
119
125
  "Send on `stdin_channel` then ping event loop"
120
- self.stdin_channel.send(msg)
126
+ try: self.stdin_channel.send(msg)
127
+ except (AssertionError, OSError, ZMQError) as e: raise DeadKernelError(f"Kernel socket closed: {e}") from e
121
128
  await asyncio.sleep(0.01)
122
129
 
123
130
  # %% ../nbs/00_core.ipynb #b828c222
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: conkernelclient
3
- Version: 0.0.9
3
+ Version: 0.0.11
4
4
  Summary: Concurrent-safe Jupyter KernelClient
5
5
  Author-email: Jeremy Howard <github@jhoward.fastmail.fm>
6
6
  License: Apache-2.0
@@ -39,5 +39,5 @@ version = {attr = "conkernelclient.__version__"}
39
39
  include = ["conkernelclient"]
40
40
 
41
41
  [tool.nbdev]
42
- allowed_metadata_keys = ['solveit_dialog_mode', 'solveit_ver']
43
- allowed_cell_metadata_keys = ["solveit_ai"]
42
+ allowed_metadata_keys = ['solveit']
43
+ allowed_cell_metadata_keys = ['solveit_ai']
@@ -1,2 +0,0 @@
1
- __version__ = "0.0.9"
2
- from .core import *