Winds the transport down: stop traffic, flush, stop the server, release the streams.
()
| 182 | writer_done.set() |
| 183 | |
| 184 | async def shutdown() -> None: |
| 185 | """Winds the transport down: stop traffic, flush, stop the server, release the streams.""" |
| 186 | # Unblock the reader into its drain: a server stuck writing stdout cannot |
| 187 | # read its stdin, so draining is what lets the flush below complete. |
| 188 | read_stream.close() |
| 189 | # Bounded window for the writer to flush already-accepted messages. |
| 190 | write_stream.close() |
| 191 | with anyio.move_on_after(_WRITER_FLUSH_TIMEOUT) as flush_scope: |
| 192 | await writer_done.wait() |
| 193 | if flush_scope.cancelled_caught: |
| 194 | await anyio.lowlevel.cancel_shielded_checkpoint() # resync coverage on 3.11 (gh-106749) |
| 195 | await _stop_server_process(process) |
| 196 | await _aclose_all(read_stream, write_stream, read_stream_writer, write_stream_reader) |
| 197 | # One pass so unblocked tasks exit via their except paths before the cancel. |
| 198 | await anyio.lowlevel.checkpoint() |
| 199 | |
| 200 | async with anyio.create_task_group() as tg: |
| 201 | tg.start_soon(stdout_reader) |
no test coverage detected