Asyncio: when use call_soon? (original) (raw)

September 20, 2024, 2:03pm 1

Hi community!

In asyncio internals or the internals of other modules that implement features on top of it, there is a lot of loop.call_soon. Does anyone know when call_soon should be used for callbacks, and when callbacks should be called directly?

Example 1: asyncio.Server accepts a connection:

Wouldn’t this do the same without the extra Task, Future, and call_soons?

Example 2: _SelectorSocketTransport receives data from a TCP socket:

In this case it was elected not to use call_soon even though, arguably, data_received is a callback.