task
Class info¶
Classes¶
| Name | Children | Inherits |
|---|---|---|
| RpcTask aclientp.task An incoming request or notification waiting to be handled. |
Re-exported classes¶
| Class | Module | Description |
|---|---|---|
| DebugEntry | aclientp.task.debug | Structured debug entry for ACP message tracking. |
| DebuggingMessageStateStore | aclientp.task.debug | Enhanced message state store with structured debugging output. |
| DefaultMessageDispatcher | aclientp.task.dispatcher | Background worker that consumes RPC tasks from a broker. |
| InMemoryMessageQueue | aclientp.task.queue | Simple in-memory broker for RPC task dispatch. |
| InMemoryMessageStateStore | aclientp.task.state | In-memory implementation of MessageStateStore. |
| MessageDispatcher | aclientp.task.dispatcher | Protocol for message dispatchers. |
| MessageQueue | aclientp.task.queue | Protocol for message queues used in RPC task dispatch. |
| MessageSender | aclientp.task.sender | Serialize JSON-RPC messages as NDJSON frames onto a byte stream. |
| MessageStateStore | aclientp.task.state | Protocol for managing message states. |
| TaskSupervisor | aclientp.task.supervisor | Track background tasks and provide graceful shutdown semantics. |
🛈 DocStrings¶
Task package.
RequestRunner
module-attribute
¶
Handles a request and returns the JSON-RPC response payload that was sent.
DebugEntry
dataclass
¶
Structured debug entry for ACP message tracking.
Source code in src/aclientp/task/debug.py
DebuggingMessageStateStore
¶
Bases: InMemoryMessageStateStore
Enhanced message state store with structured debugging output.
Provides much richer debugging information than raw JSON logging: - Request/response correlation - Timing information - Status tracking - Structured data output - Error details
Source code in src/aclientp/task/debug.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
begin_incoming
¶
begin_incoming(method: str, params: Any) -> IncomingMessage
Begin processing incoming request with debug logging.
Source code in src/aclientp/task/debug.py
complete_incoming
¶
complete_incoming(record: IncomingMessage, result: Any) -> None
Complete incoming request with debug logging.
Source code in src/aclientp/task/debug.py
fail_incoming
¶
fail_incoming(record: IncomingMessage, error: Exception) -> None
Fail incoming request with debug logging.
Source code in src/aclientp/task/debug.py
register_outgoing
¶
Register outgoing request with debug logging.
Source code in src/aclientp/task/debug.py
reject_all_outgoing
¶
Reject all outgoing requests with debug logging.
Source code in src/aclientp/task/debug.py
reject_outgoing
¶
reject_outgoing(request_id: int, error: RequestError) -> None
Reject outgoing request with debug logging.
Source code in src/aclientp/task/debug.py
resolve_outgoing
¶
Resolve outgoing request with debug logging.
Source code in src/aclientp/task/debug.py
DefaultMessageDispatcher
dataclass
¶
Bases: MessageDispatcher
Background worker that consumes RPC tasks from a broker.
Every message is handled in its own task, so a slow handler never blocks the others; tasks are started in the order the messages were received.
Source code in src/aclientp/task/dispatcher.py
InMemoryMessageQueue
¶
Simple in-memory broker for RPC task dispatch.
Source code in src/aclientp/task/queue.py
InMemoryMessageStateStore
¶
Bases: MessageStateStore
In-memory implementation of MessageStateStore.
Source code in src/aclientp/task/state.py
MessageDispatcher
¶
Bases: Protocol
Protocol for message dispatchers.
Source code in src/aclientp/task/dispatcher.py
MessageQueue
¶
Bases: Protocol
Protocol for message queues used in RPC task dispatch.
Source code in src/aclientp/task/queue.py
MessageSender
¶
Serialize JSON-RPC messages as NDJSON frames onto a byte stream.
Frames are written by a single writer task, in the order they were enqueued. Writing outside the caller's task keeps frames intact: cancelling a caller can never leave a half-written frame on the stream (anyio byte streams may write in several steps).
Once the stream fails or the sender is closed, every queued and every later send
fails with :class:ConnectionError instead of waiting forever.
Source code in src/aclientp/task/sender.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
__init__
¶
__init__(writer: ByteSendStream, supervisor: TaskSupervisor, *, flush_timeout: float = 5.0) -> None
Start the writer task.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
writer
|
ByteSendStream
|
Byte stream the frames are written to. |
required |
supervisor
|
TaskSupervisor
|
Supervisor owning the writer task. |
required |
flush_timeout
|
float
|
How long |
5.0
|
Source code in src/aclientp/task/sender.py
close
async
¶
Stop accepting messages and flush the ones already queued.
Queued frames get up to flush_timeout seconds to be written; whatever is
still pending afterwards fails with ConnectionError.
Source code in src/aclientp/task/sender.py
send
async
¶
Write a message and wait until it is on the stream.
Raises:
| Type | Description |
|---|---|
ConnectionError
|
The sender is closed or the stream failed. |
TypeError
|
The payload is not JSON-serializable. |
Source code in src/aclientp/task/sender.py
send_nowait
¶
Enqueue a message without waiting for it to be written.
The message is committed to the stream as soon as this returns, so it is written
even if the caller is cancelled right after (it is flushed by close() too).
Returns:
| Type | Description |
|---|---|
Future[None]
|
A future that completes once the frame was written, or fails with |
Future[None]
|
|
Raises:
| Type | Description |
|---|---|
ConnectionError
|
The sender is closed or the stream failed earlier. |
TypeError
|
The payload is not JSON-serializable. |
Source code in src/aclientp/task/sender.py
MessageStateStore
¶
Bases: Protocol
Protocol for managing message states.
Source code in src/aclientp/task/state.py
RpcTask
dataclass
¶
An incoming request or notification waiting to be handled.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
RpcTaskKind
|
Whether the message is a request or a notification. |
message |
dict[str, Any]
|
The raw JSON-RPC message. |
done |
Future[None] | None
|
Resolved once the message has been handled. Set for notifications, so the connection can wait for notifications received before a given response. |
Source code in src/aclientp/task/__init__.py
TaskSupervisor
¶
Track background tasks and provide graceful shutdown semantics.
Inspired by fasta2a's task manager, this supervisor keeps a registry of asyncio tasks created for request handling so they can be cancelled and awaited reliably when the connection closes.
Source code in src/aclientp/task/supervisor.py
shutdown
async
¶
Cancel all tracked tasks and wait for them to finish.
The calling task is left alone: a handler may close its own connection, and cancelling and awaiting itself would end in a self-await cancellation cycle.