Python 3.4+Async programmingterm
asyncio.BaseProtocol
protocols and transports
The base class of all asyncio protocols: the callbacks connection_made(), connection_lost(), pause_writing() and resume_writing() invoked by a transport.
Syntax
class MyProto(asyncio.Protocol): def connection_made(self, transport): ...
Learners rarely need this layer: streams (asyncio.open_connection() and asyncio.start_server()) cover TCP, and asyncio.create_subprocess_exec() covers processes. Nobody subclasses BaseProtocol directly — you pick Protocol, BufferedProtocol, DatagramProtocol or SubprocessProtocol. Its methods are callbacks: the loop calls them, not your code; they are plain functions (not async def), so await is impossible inside — start long work from a callback with asyncio.create_task().
Examples
import asyncio
print([c.__name__ for c in asyncio.Protocol.__mro__]) # → ['Protocol', 'BaseProtocol', 'object']
print(issubclass(asyncio.DatagramProtocol, asyncio.BaseProtocol)) # → True
async def main():
await asyncio.sleep(0.01)
asyncio.run(main())
See also
Open in the full glossarydocs.python.orgReport an inaccuracy