On this page
asyncio.BufferedProtocol
Prev: asyncio.BrokenBarrierError | Up: asyncio | Next: asyncio.CancelledError
Rel: asyncio.AbstractEventLoop, asyncio.AbstractServer, asyncio.all_tasks, asyncio.as_completed
Ref: docs.python.org — asyncio.BufferedProtocol
Tags: #public #python3 #stdlib #asyncio
Import
import asyncio
from asyncio import BufferedProtocol
Signature & Overview
asyncio.BufferedProtocol()
Interface for stream protocol with manual buffer control.
Methods & Attributes
BufferedProtocol.buffer_updated(self, nbytes)— Called when the buffer was updated with the received data.BufferedProtocol.connection_lost(self, exc)— Called when the connection is lost or closed.BufferedProtocol.connection_made(self, transport)— Called when a connection is made.BufferedProtocol.eof_received(self)— Called when the other end calls write_eof() or equivalent.BufferedProtocol.get_buffer(self, sizehint)— Called to allocate a new receive buffer.BufferedProtocol.pause_writing(self)— Called when the transport's buffer goes over the high-water mark.BufferedProtocol.resume_writing(self)— Called when the transport's buffer drains below the low-water mark.
Usage
import asyncio
# Zero-copy protocol subclass using get_buffer() / buffer_updated()
assert issubclass(asyncio.BufferedProtocol, asyncio.BaseProtocol)
Gotchas
- For high-throughput binary protocols: Avoids allocating a new
bytesobject perdata_received()call by letting you supply a pre-allocatedbytearray/memoryview.
REPL Inspect
from asyncio import BufferedProtocol
help(BufferedProtocol)
Linked from
Related notes
- tuts/python3/stdlib_module/asyncio/BrokenBarrierError Linked here; links to this page; shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio/CancelledError Linked here; links to this page; shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/asyncio/AbstractEventLoop Linked here; shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio/AbstractServer Linked here; shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio/all_tasks Linked here; shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio/as_completed Linked here; shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio/Barrier shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio/BaseEventLoop shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio/BaseProtocol shared tags: #asyncio, #stdlib