外观
worker API
模块说明
text
Native managed worker lifecycle. Legacy runtime domains use their own loader.Worker
python
class WorkerSDK 说明:
text
Own a fresh peer and async callbacks, running events serially.
Callbacks receive (peer, payload). Use spawn() for cooperative background
work; detached tasks/threads are not covered by drain. The host must pause and join delivery
before drain, and separately join world actions. No event is auto-acknowledged.
run() owns peer cleanup; cancellation closes IPC and joins cooperative tasks.
Do not consume this peer's queues elsewhere. CPU-blocking/uncooperative code
still requires the host's process termination boundary.Worker.__init__
python
def __init__(
self,
peer,
*,
on_event,
on_validate,
on_activate,
on_drain,
on_service = None,
on_bus = None,
on_maintenance = None,
views = None,
max_background_tasks = 32,
)Worker.session
python
@property
def session(self)SDK 说明:
text
Immutable hello metadata, available in all lifecycle callbacks.
Capabilities are the handshake snapshot, not a live permission lease.Worker.spawn
python
def spawn(self, coroutine, *, name=None)SDK 说明:
text
Start bounded cooperative work during activation or active delivery.
Child errors fail the worker even when the returned Task is awaited.
Drain cancels and joins these tasks; restart timers on resumed events if
needed. No work may be started during validation, drain or shutdown.Worker.run
python
async def run(self)SDK 说明:
text
Handshake and serve until cancellation, transport failure or callback error.Worker.peer
python
self.peer公开实例属性,在 __init__ 中设置。
Worker.log
python
self.log公开实例属性,在 __init__ 中设置。