85742ab165
CPU Test / Lint - next (push) Waiting to run
Dashboard / Chromatic (push) Waiting to run
CPU Test / Lint - fast (push) Waiting to run
CPU Test / Build documentation (push) Waiting to run
CPU Test / Test (Store, legacy, Python 3.10) (push) Waiting to run
CPU Test / Test (Utilities, legacy, Python 3.10) (push) Waiting to run
CPU Test / Test (Weave, legacy, Python 3.10) (push) Waiting to run
CPU Test / Test (AgentOps, stable, Python 3.11) (push) Waiting to run
CPU Test / Test (LLM proxy, stable, Python 3.11) (push) Waiting to run
CPU Test / Test (Others, stable, Python 3.11) (push) Waiting to run
CPU Test / Test (Store, stable, Python 3.11) (push) Waiting to run
CPU Test / Test (Utilities, stable, Python 3.11) (push) Waiting to run
CPU Test / Test (Weave, stable, Python 3.11) (push) Waiting to run
CPU Test / Test (AgentOps, stable, Python 3.12) (push) Waiting to run
CPU Test / Test (LLM proxy, stable, Python 3.12) (push) Waiting to run
CPU Test / Test (Others, stable, Python 3.12) (push) Waiting to run
CPU Test / Test (Store, stable, Python 3.12) (push) Waiting to run
CPU Test / Test (Utilities, stable, Python 3.12) (push) Waiting to run
CPU Test / Test (Weave, stable, Python 3.12) (push) Waiting to run
CPU Test / Test (AgentOps, latest, Python 3.13) (push) Waiting to run
CPU Test / Test (LLM proxy, latest, Python 3.13) (push) Waiting to run
CPU Test / Test (Others, latest, Python 3.13) (push) Waiting to run
CPU Test / Test (Store, latest, Python 3.13) (push) Waiting to run
CPU Test / Lint - slow (push) Waiting to run
CPU Test / Lint - JavaScript (push) Waiting to run
CPU Test / Test (AgentOps, legacy, Python 3.10) (push) Waiting to run
CPU Test / Test (LLM proxy, legacy, Python 3.10) (push) Waiting to run
CPU Test / Test (Others, legacy, Python 3.10) (push) Waiting to run
CPU Test / Test (Utilities, latest, Python 3.13) (push) Waiting to run
CPU Test / Test (Weave, latest, Python 3.13) (push) Waiting to run
CPU Test / Test (JavaScript) (push) Waiting to run
Deploy Documentation / deploy (push) Has been cancelled
70 lines
1.9 KiB
Python
70 lines
1.9 KiB
Python
# Copyright (c) Microsoft. All rights reserved.
|
|
|
|
import multiprocessing as mp
|
|
import threading
|
|
from multiprocessing.context import BaseContext
|
|
from typing import Optional, Protocol
|
|
|
|
|
|
class ExecutionEvent(Protocol):
|
|
"""Protocol capturing the cooperative stop contract shared by strategies.
|
|
|
|
Implementations mirror the API of ``threading.Event`` and
|
|
``multiprocessing.Event`` so the rest of the execution layer can remain
|
|
agnostic to the underlying concurrency primitive.
|
|
|
|
Methods:
|
|
|
|
set: Signal cancellation. The call must be idempotent.
|
|
clear: Reset the event to the unsignaled state.
|
|
is_set: Return ``True`` when cancellation has been requested.
|
|
wait: Block until the event is signaled or an optional timeout elapses.
|
|
"""
|
|
|
|
def set(self) -> None: ...
|
|
def clear(self) -> None: ...
|
|
def is_set(self) -> bool: ...
|
|
def wait(self, timeout: Optional[float] = None) -> bool: ...
|
|
|
|
|
|
class ThreadingEvent:
|
|
"""Thread-safe implementation of [`ExecutionEvent`][agentlightning.ExecutionEvent]."""
|
|
|
|
__slots__ = ("_evt",)
|
|
|
|
def __init__(self) -> None:
|
|
self._evt = threading.Event()
|
|
|
|
def set(self) -> None:
|
|
self._evt.set()
|
|
|
|
def clear(self) -> None:
|
|
self._evt.clear()
|
|
|
|
def is_set(self) -> bool:
|
|
return self._evt.is_set()
|
|
|
|
def wait(self, timeout: Optional[float] = None) -> bool:
|
|
return self._evt.wait(timeout)
|
|
|
|
|
|
class MultiprocessingEvent:
|
|
"""Process-safe implementation of [`ExecutionEvent`][agentlightning.ExecutionEvent]."""
|
|
|
|
__slots__ = ("_evt",)
|
|
|
|
def __init__(self, *, ctx: Optional[BaseContext] = None) -> None:
|
|
self._evt = (ctx or mp).Event()
|
|
|
|
def set(self) -> None:
|
|
self._evt.set()
|
|
|
|
def clear(self) -> None:
|
|
self._evt.clear()
|
|
|
|
def is_set(self) -> bool:
|
|
return self._evt.is_set()
|
|
|
|
def wait(self, timeout: Optional[float] = None) -> bool:
|
|
return self._evt.wait(timeout)
|