I use Python's asyncio library to create a server that can handle telnet requests. Because asyncio's server loop is single threaded, I thought it would make more sense that when asyncio tells me that I got data (asyncio.Protocol.data_received
) to simply schedule a task, rather than block receiving further data until I finish handling this bit of data and transmitting my reply.
But because the only I/O operation that I do with this data is transmitting a reply or sending things to other clients, I am not sure there is a reason to not just block the single thread until done. If it is in any way possible for the asyncio loop to to use more than one thread, then if I schedule tasks, they will actually be able to be performed in parallel, but I don't think this is the case.
I considered that maybe for locking purposes I would prefer using coroutines, but if I am single threaded locking shouldn't be needed.
If it is in any way possible for the asyncio loop to to use more than one thread, then if I schedule tasks, they will actually be able to be performed in parallel, but I don't think this is the case.
-- That's too bad. There's really only so much you can do with a single thread. The whole point of async is for your server loop to return immediately so that it can handle more requests, and it can't do that if it has to block. – Robert Harvey Nov 12 at 15:53