e2b-code-interpreter 0.0.5__tar.gz → 0.0.7__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.1
2
2
  Name: e2b-code-interpreter
3
- Version: 0.0.5
3
+ Version: 0.0.7
4
4
  Summary: E2B Code Interpreter - Stateful code execution
5
5
  Home-page: https://e2b.dev/
6
6
  License: Apache-2.0
@@ -52,13 +52,13 @@ class CodeInterpreter(Sandbox):
52
52
 
53
53
 
54
54
  class JupyterExtension:
55
- _default_kernel_id: Optional[str] = None
56
- _connected_kernels: Dict[str, Future[JupyterKernelWebSocket]] = {}
57
55
 
58
56
  def __init__(self, sandbox: CodeInterpreter, timeout: Optional[float] = TIMEOUT):
59
57
  self._sandbox = sandbox
60
58
  self._kernel_id_set = Future()
61
59
  self._start_connecting_to_default_kernel(timeout=timeout)
60
+ self._connected_kernels: Dict[str, Future[JupyterKernelWebSocket]] = {}
61
+ self._default_kernel_id: Optional[str] = None
62
62
 
63
63
  def exec_cell(
64
64
  self,
@@ -139,7 +139,7 @@ class JupyterExtension:
139
139
  :param timeout: Timeout for the kernel creation request.
140
140
  :return: Kernel id of the created kernel
141
141
  """
142
- data = {"cwd": cwd}
142
+ data = {"path": cwd}
143
143
  if kernel_name:
144
144
  data["kernel_name"] = kernel_name
145
145
  logger.debug(f"Creating kernel with data: {data}")
@@ -5,14 +5,13 @@ import time
5
5
  import uuid
6
6
  from concurrent.futures import Future
7
7
  from queue import Queue
8
- from typing import Callable, Dict, List, Any, Optional
8
+ from typing import Callable, Dict, Any, Optional
9
9
 
10
10
  from e2b import ProcessMessage
11
11
  from e2b.constants import TIMEOUT
12
12
  from e2b.sandbox import TimeoutException
13
13
  from e2b.sandbox.websocket_client import WebSocket
14
14
  from e2b.utils.future import DeferredFuture
15
- from pydantic import ConfigDict, PrivateAttr, BaseModel
16
15
 
17
16
  from e2b_code_interpreter.models import Execution, Result, Error
18
17
 
@@ -43,30 +42,29 @@ class CellExecution:
43
42
  self.on_result = on_result
44
43
 
45
44
 
46
- class JupyterKernelWebSocket(BaseModel):
47
- model_config = ConfigDict(arbitrary_types_allowed=True)
45
+ class JupyterKernelWebSocket:
48
46
 
49
- url: str
50
-
51
- _cells: Dict[str, CellExecution] = {}
52
- _waiting_for_replies: Dict[str, DeferredFuture] = PrivateAttr(default_factory=dict)
53
- _queue_in: Queue = PrivateAttr(default_factory=Queue)
54
- _queue_out: Queue = PrivateAttr(default_factory=Queue)
55
- _process_cleanup: List[Callable[[], Any]] = PrivateAttr(default_factory=list)
56
- _closed: bool = PrivateAttr(default=False)
47
+ def __init__(self, url: str):
48
+ self.url = url
49
+ self._cells: Dict[str, CellExecution] = {}
50
+ self._waiting_for_replies: Dict[str, DeferredFuture] = {}
51
+ self._queue_in = Queue()
52
+ self._queue_out = Queue()
53
+ self._stopped = threading.Event()
57
54
 
58
55
  def process_messages(self):
59
- while True:
60
- data = self._queue_out.get()
56
+ while not self._stopped.is_set():
57
+ if self._queue_out.empty():
58
+ time.sleep(0.01)
59
+ continue
61
60
 
61
+ data = self._queue_out.get()
62
62
  logger.debug(f"WebSocket received message: {data}".strip())
63
63
  self._receive_message(json.loads(data))
64
64
  self._queue_out.task_done()
65
65
 
66
66
  def connect(self, timeout: float = TIMEOUT):
67
67
  started = threading.Event()
68
- stopped = threading.Event()
69
- self._process_cleanup.append(stopped.set)
70
68
 
71
69
  threading.Thread(
72
70
  target=self.process_messages, daemon=True, name="e2b-process-messages"
@@ -78,7 +76,7 @@ class JupyterKernelWebSocket(BaseModel):
78
76
  queue_in=self._queue_in,
79
77
  queue_out=self._queue_out,
80
78
  started=started,
81
- stopped=stopped,
79
+ stopped=self._stopped
82
80
  ).run,
83
81
  daemon=True,
84
82
  name="e2b-code-interpreter-websocket",
@@ -91,7 +89,7 @@ class JupyterKernelWebSocket(BaseModel):
91
89
  while (
92
90
  not started.is_set()
93
91
  and time.time() - start_time < timeout
94
- and not self._closed
92
+ and not self._stopped.is_set()
95
93
  ):
96
94
  time.sleep(0.1)
97
95
 
@@ -245,12 +243,7 @@ class JupyterKernelWebSocket(BaseModel):
245
243
 
246
244
  def close(self):
247
245
  logger.debug("Closing WebSocket")
248
- self._closed = True
249
-
250
- for cancel in self._process_cleanup:
251
- cancel()
252
-
253
- self._process_cleanup.clear()
246
+ self._stopped.set()
254
247
 
255
248
  for handler in self._waiting_for_replies.values():
256
249
  logger.debug(f"Cancelling waiting for execution result for {handler}")
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "e2b-code-interpreter"
3
- version = "0.0.5"
3
+ version = "0.0.7"
4
4
  description = "E2B Code Interpreter - Stateful code execution"
5
5
  authors = ["e2b <hello@e2b.dev>"]
6
6
  license = "Apache-2.0"