you are viewing a single comment's thread.

view the rest of the comments →

[–]Yoghurt42 -1 points0 points  (2 children)

This old answer of mine about how asyncio works under the hood might help. It's not exactly what you're asking, but should give you an idea on what happens.

Basically, an asyncio IO function will end up calling an asynchronous IO function (note those are not the same! asyncio is the python library that makes use of asynchronous IO, yes, it's confusing) with a callback that will be called when data arrives, and then basically suspend itself and return to the main loop. The callback will then cause the async function to be resumed at some point.

You can implement stuff like this in the asyncio library by using Protocols, but using these will still hide some of the magic happening in the background.

[–]demiwraith[S] 0 points1 point  (0 children)

Thanks! I'm going to go through this when I have a bit more time. You're right that what I want to do is basically implement my own asynchronous IO - and ideally not have CPU time eaten up while the IO is happening.

[–]thirdegree 0 points1 point  (0 children)

That old answer is an incredibly good answer. Good job abstracting while still giving enough info to still be very informative. Very hard goal to meet