txl-kernel 0.2.15__tar.gz → 0.3.4__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,10 +1,11 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.4
2
2
  Name: txl_kernel
3
- Version: 0.2.15
3
+ Version: 0.3.4
4
4
  Summary: TXL plugin for a kernel driver
5
5
  Project-URL: Source, https://github.com/davidbrochart/jpterm/plugins/kernel
6
6
  Author-email: David Brochart <david.brochart@gmail.com>
7
- License: MIT
7
+ License-Expression: MIT
8
+ License-File: LICENSE.txt
8
9
  Classifier: Development Status :: 4 - Beta
9
10
  Classifier: Programming Language :: Python
10
11
  Classifier: Programming Language :: Python :: 3.10
@@ -14,10 +15,9 @@ Classifier: Programming Language :: Python :: 3.13
14
15
  Classifier: Programming Language :: Python :: Implementation :: CPython
15
16
  Classifier: Programming Language :: Python :: Implementation :: PyPy
16
17
  Requires-Python: >=3.10
17
- Requires-Dist: asphalt<5.0.0,>=4.0.0
18
- Requires-Dist: pycrdt<0.11.0,>=0.10.9
18
+ Requires-Dist: pycrdt<0.13.0,>=0.10.9
19
19
  Requires-Dist: python-dateutil>=2.8.2
20
- Requires-Dist: txl<0.3.0,>=0.2.18
20
+ Requires-Dist: txl==0.3.1
21
21
  Description-Content-Type: text/markdown
22
22
 
23
23
  # TXL plugin for a kernel driver
@@ -0,0 +1,20 @@
1
+ [build-system]
2
+ requires = [ "hatchling",]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "txl_kernel"
7
+ version = "0.3.4"
8
+ description = "TXL plugin for a kernel driver"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "MIT"
12
+ keywords = []
13
+ classifiers = [ "Development Status :: 4 - Beta", "Programming Language :: Python", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy",]
14
+ dependencies = [ "txl ==0.3.1", "python-dateutil >=2.8.2", "pycrdt >=0.10.9,<0.13.0",]
15
+ [[project.authors]]
16
+ name = "David Brochart"
17
+ email = "david.brochart@gmail.com"
18
+
19
+ [project.urls]
20
+ Source = "https://github.com/davidbrochart/jpterm/plugins/kernel"
@@ -1,8 +1,9 @@
1
- import asyncio
2
1
  import time
3
2
  from typing import Dict
4
3
 
5
- from asphalt.core import Event, Signal
4
+ from anyio import move_on_after
5
+ from anyioutils import Event, Queue, create_task
6
+ from fps import Signal
6
7
  from pycrdt import Array, Map
7
8
 
8
9
  from .message import create_message
@@ -13,11 +14,12 @@ def deadline_to_timeout(deadline: float) -> float:
13
14
 
14
15
 
15
16
  class Comm:
16
- def __init__(self, comm_id: str, shell_channel, session_id: str, send_message):
17
+ def __init__(self, comm_id: str, shell_channel, session_id: str, send_message, task_group):
17
18
  self.comm_id = comm_id
18
19
  self.shell_channel = shell_channel
19
20
  self.session_id = session_id
20
21
  self.send_message = send_message
22
+ self.task_group = task_group
21
23
  self.msg_cnt = 0
22
24
 
23
25
  def send(self, buffers):
@@ -29,24 +31,20 @@ class Comm:
29
31
  buffers=buffers,
30
32
  )
31
33
  self.msg_cnt += 1
32
- asyncio.create_task(self.send_message(msg, self.shell_channel, change_date_to_str=True))
33
-
34
-
35
- class BusyEvent(Event):
36
- def __init__(self, source, topic, busy: bool):
37
- super().__init__(source, topic)
38
- self.busy = busy
34
+ create_task(
35
+ self.send_message(msg, self.shell_channel, change_date_to_str=True), self.task_group
36
+ )
39
37
 
40
38
 
41
39
  class KernelMixin:
42
- busy = Signal(BusyEvent)
43
-
44
- def __init__(self):
40
+ def __init__(self, task_group):
41
+ self.task_group = task_group
42
+ self.busy = Signal[bool]()
45
43
  self.msg_cnt = 0
46
- self.execute_requests: Dict[str, Dict[str, asyncio.Queue]] = {}
47
- self.recv_queue = asyncio.Queue()
48
- self.started = asyncio.Event()
49
- asyncio.create_task(self.recv())
44
+ self.execute_requests: Dict[str, Dict[str, Queue]] = {}
45
+ self.recv_queue = Queue()
46
+ self.started = Event()
47
+ create_task(self.recv(), task_group)
50
48
 
51
49
  def create_message(self, *args, **kwargs):
52
50
  return create_message(*args, **kwargs)
@@ -64,23 +62,19 @@ class KernelMixin:
64
62
  await self.send_message(msg, self.shell_channel, change_date_to_str=True)
65
63
  msg_id = msg["header"]["msg_id"]
66
64
  self.execute_requests[msg_id] = {
67
- "iopub": asyncio.Queue(),
68
- "shell": asyncio.Queue(),
65
+ "iopub": Queue(),
66
+ "shell": Queue(),
69
67
  }
70
- try:
71
- msg = await asyncio.wait_for(
72
- self.execute_requests[msg_id]["shell"].get(), new_timeout
73
- )
74
- except asyncio.TimeoutError:
68
+ with move_on_after(new_timeout) as scope:
69
+ msg = await self.execute_requests[msg_id]["shell"].get()
70
+ if scope.cancelled_caught:
75
71
  del self.execute_requests[msg_id]
76
72
  error_message = f"Kernel didn't respond in {timeout} seconds"
77
73
  raise RuntimeError(error_message)
78
74
  if msg["header"]["msg_type"] == "kernel_info_reply":
79
- try:
80
- msg = await asyncio.wait_for(self.execute_requests[msg_id]["iopub"].get(), 0.2)
81
- except asyncio.TimeoutError:
82
- pass
83
- else:
75
+ with move_on_after(0.2) as scope:
76
+ msg = await self.execute_requests[msg_id]["iopub"].get()
77
+ if not scope.cancelled_caught:
84
78
  break
85
79
  del self.execute_requests[msg_id]
86
80
  new_timeout = deadline_to_timeout(deadline)
@@ -93,7 +87,13 @@ class KernelMixin:
93
87
  if msg_type == "comm_open":
94
88
  for comm_handler in self.comm_handlers:
95
89
  comm_id = msg["content"]["comm_id"]
96
- comm = Comm(comm_id, self.shell_channel, self.session_id, self.send_message)
90
+ comm = Comm(
91
+ comm_id,
92
+ self.shell_channel,
93
+ self.session_id,
94
+ self.send_message,
95
+ self.task_group,
96
+ )
97
97
  comm_handler.comm_open(msg, comm)
98
98
  elif msg_type == "comm_msg":
99
99
  for comm_handler in self.comm_handlers:
@@ -101,9 +101,9 @@ class KernelMixin:
101
101
  elif msg_type == "status":
102
102
  execution_state = msg["content"]["execution_state"]
103
103
  if execution_state == "idle":
104
- self.busy.dispatch(False)
104
+ await self.busy.emit(False)
105
105
  elif execution_state == "busy":
106
- self.busy.dispatch(True)
106
+ await self.busy.emit(True)
107
107
  msg_id = msg["parent_header"].get("msg_id")
108
108
  if msg_id in self.execute_requests:
109
109
  # msg["header"] = str_to_date(msg["header"])
@@ -136,19 +136,16 @@ class KernelMixin:
136
136
  msg_id = msg["header"]["msg_id"]
137
137
  self.msg_cnt += 1
138
138
  self.execute_requests[msg_id] = {
139
- "iopub": asyncio.Queue(),
140
- "shell": asyncio.Queue(),
139
+ "iopub": Queue(),
140
+ "shell": Queue(),
141
141
  }
142
142
  await self.send_message(msg, self.shell_channel, change_date_to_str=True)
143
143
  if wait_for_executed:
144
144
  deadline = time.monotonic() + timeout
145
145
  while True:
146
- try:
147
- msg = await asyncio.wait_for(
148
- self.execute_requests[msg_id]["iopub"].get(),
149
- deadline_to_timeout(deadline),
150
- )
151
- except asyncio.TimeoutError:
146
+ with move_on_after(deadline_to_timeout(deadline)) as scope:
147
+ msg = await self.execute_requests[msg_id]["iopub"].get()
148
+ if scope.cancelled_caught:
152
149
  del self.execute_requests[msg_id]
153
150
  error_message = f"Kernel didn't respond in {timeout} seconds"
154
151
  raise RuntimeError(error_message)
@@ -158,12 +155,9 @@ class KernelMixin:
158
155
  and msg["content"]["execution_state"] == "idle")
159
156
  ):
160
157
  break
161
- try:
162
- msg = await asyncio.wait_for(
163
- self.execute_requests[msg_id]["shell"].get(),
164
- deadline_to_timeout(deadline),
165
- )
166
- except asyncio.TimeoutError:
158
+ with move_on_after(deadline_to_timeout(deadline)) as scope:
159
+ msg = await self.execute_requests[msg_id]["shell"].get()
160
+ if scope.cancelled_caught:
167
161
  del self.execute_requests[msg_id]
168
162
  error_message = f"Kernel didn't respond in {timeout} seconds"
169
163
  raise RuntimeError(error_message)
@@ -1,34 +0,0 @@
1
- [build-system]
2
- requires = ["hatchling"]
3
- build-backend = "hatchling.build"
4
-
5
- [project]
6
- name = "txl_kernel"
7
- version = "0.2.15"
8
- description = "TXL plugin for a kernel driver"
9
- readme = "README.md"
10
- requires-python = ">=3.10"
11
- license = "MIT"
12
- keywords = []
13
- authors = [
14
- { name = "David Brochart", email = "david.brochart@gmail.com" },
15
- ]
16
- classifiers = [
17
- "Development Status :: 4 - Beta",
18
- "Programming Language :: Python",
19
- "Programming Language :: Python :: 3.10",
20
- "Programming Language :: Python :: 3.11",
21
- "Programming Language :: Python :: 3.12",
22
- "Programming Language :: Python :: 3.13",
23
- "Programming Language :: Python :: Implementation :: CPython",
24
- "Programming Language :: Python :: Implementation :: PyPy",
25
- ]
26
- dependencies = [
27
- "txl >=0.2.18,<0.3.0",
28
- "asphalt >=4.0.0,<5.0.0",
29
- "python-dateutil >=2.8.2",
30
- "pycrdt >=0.10.9,<0.11.0",
31
- ]
32
-
33
- [project.urls]
34
- Source = "https://github.com/davidbrochart/jpterm/plugins/kernel"
File without changes
File without changes
File without changes