|
17 | 17 | get_quantum_cooldown, |
18 | 18 | ) |
19 | 19 | try: |
20 | | - from .iris import PyRuntime, PySystemMessage, version, allocate_buffer, PyMailbox, register_offload |
| 20 | + from .iris import ( |
| 21 | + PyRuntime, |
| 22 | + PySystemMessage, |
| 23 | + PyRequest, |
| 24 | + version, |
| 25 | + allocate_buffer, |
| 26 | + PyMailbox, |
| 27 | + register_offload, |
| 28 | + ) |
21 | 29 | except ImportError: |
22 | | - from iris import PyRuntime, PySystemMessage, version, allocate_buffer, PyMailbox, register_offload |
23 | | - |
| 30 | + from iris import ( |
| 31 | + PyRuntime, |
| 32 | + PySystemMessage, |
| 33 | + PyRequest, |
| 34 | + version, |
| 35 | + allocate_buffer, |
| 36 | + PyMailbox, |
| 37 | + register_offload, |
| 38 | + ) |
| 39 | + |
| 40 | + |
24 | 41 | class Runtime: |
25 | 42 | def __init__(self): |
26 | 43 | self._inner = PyRuntime() |
27 | 44 |
|
| 45 | + def call(self, pid: int, data: Union[bytes, bytearray, memoryview], timeout: Optional[float] = None) -> Awaitable[bytes]: |
| 46 | + """ |
| 47 | + Send a request to an actor and await a response. |
| 48 | +
|
| 49 | + The target actor's handler will receive a `PyRequest` object (if it's a Python actor) |
| 50 | + or a `Message::Request` (if it's a Rust actor). |
| 51 | +
|
| 52 | + Args: |
| 53 | + pid: Target actor PID. |
| 54 | + data: Request payload. |
| 55 | + timeout: Timeout in seconds (defaults to 5.0). |
| 56 | +
|
| 57 | + Returns: |
| 58 | + The response payload as bytes. |
| 59 | + """ |
| 60 | + return self._inner.call(pid, data, timeout) |
| 61 | + |
28 | 62 | def spawn(self, handler, budget: int = 100, release_gil: bool = False) -> int: |
29 | 63 | """ |
30 | 64 | Spawn a new push-based actor (Green Thread). |
@@ -285,6 +319,37 @@ def rollback_behavior(self, pid: int, steps: int = 1) -> int: |
285 | 319 | """ |
286 | 320 | return self._inner.rollback_behavior(pid, steps) |
287 | 321 |
|
| 322 | + def list_actors(self) -> list[int]: |
| 323 | + """List all active actor PIDs in the system.""" |
| 324 | + return self._inner.list_actors() |
| 325 | + |
| 326 | + def actor_info(self, pid: int) -> Optional[dict[str, str]]: |
| 327 | + """Get detailed info about an actor as a dictionary.""" |
| 328 | + return self._inner.actor_info(pid) |
| 329 | + |
| 330 | + def set_actor_health(self, pid: int, status: str): |
| 331 | + """Set health status for an actor. |
| 332 | +
|
| 333 | + status: 'starting', 'ready', 'busy', 'degraded'. |
| 334 | + """ |
| 335 | + self._inner.set_actor_health(pid, status) |
| 336 | + |
| 337 | + def get_metrics(self) -> dict[str, int]: |
| 338 | + """Retrieve runtime-wide metrics (actor_count, messages_sent, etc.).""" |
| 339 | + return self._inner.get_metrics() |
| 340 | + |
| 341 | + def set_system_capacity(self, cap: int): |
| 342 | + """Set the maximum number of actors allowed in the system.""" |
| 343 | + self._inner.set_system_capacity(cap) |
| 344 | + |
| 345 | + def set_load_shedding(self, enabled: bool): |
| 346 | + """Enable or disable load shedding.""" |
| 347 | + self._inner.set_load_shedding(enabled) |
| 348 | + |
| 349 | + def is_load_shedding_active(self) -> bool: |
| 350 | + """Check if load shedding is currently active (system at capacity).""" |
| 351 | + return self._inner.is_load_shedding_active() |
| 352 | + |
288 | 353 | def selective_recv(self, pid: int, matcher: Callable, timeout: Optional[float] = None) -> Awaitable[Optional[Union[bytes, PySystemMessage]]]: |
289 | 354 | """ |
290 | 355 | Return an awaitable that resolves when `matcher(msg)` is True. |
@@ -393,4 +458,11 @@ def send_user_with_backpressure(self, pid: int, data: bytes) -> tuple[bool, Opti |
393 | 458 | level = self.mailbox_backpressure(pid) |
394 | 459 | return success, level |
395 | 460 |
|
396 | | -__all__ = ["Runtime", "PySystemMessage", "version", "allocate_buffer", "PyMailbox"] |
| 461 | +__all__ = [ |
| 462 | + "Runtime", |
| 463 | + "PySystemMessage", |
| 464 | + "PyRequest", |
| 465 | + "version", |
| 466 | + "allocate_buffer", |
| 467 | + "PyMailbox", |
| 468 | +] |
0 commit comments