You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been trying to understand how this project works, and also how we can support newer language versions. I've done some reading into how asyncio works, and I thought I would share that here. Sorry if this is not news to anybody, I'm not much of a python developer.
The byte code of calling the functions is actually unchanged. The functions marked with async just have to return a co-routine object. The GET_AWAITABLE opcode seems to cast the other await-able types e.g. generators or classes that implement self.__await__.
We might be able to implement this fairly easily by just wrapping the Function type in a co-routine type. To get any actual concurrency out of this implementation though, we need to implement the event loop API.
This is the hard part which actually allows creation of futures and tasks. I'm not sure if the await for byte code that was already implemented in 3.4 has all the features we need, but it looks like we can get pretty far with the byte code we have already.
The last piece of the puzzle is select() which allows us to wait on a socket while executing another co-routine.
I've been trying to understand how this project works, and also how we can support newer language versions. I've done some reading into how asyncio works, and I thought I would share that here. Sorry if this is not news to anybody, I'm not much of a python developer.
The co-routine introduced in python3.5 seem to be the biggest language feature we need to support to become current. The op codes can be found here: https://docs.python.org/3/library/dis.html#opcode-GET_AWAITABLE
A basic example program looks like:
And produces the following bytecode:
The byte code of calling the functions is actually unchanged. The functions marked with
async
just have to return a co-routine object. TheGET_AWAITABLE
opcode seems to cast the other await-able types e.g. generators or classes that implementself.__await__
.We might be able to implement this fairly easily by just wrapping the
Function
type in aco-routine
type. To get any actual concurrency out of this implementation though, we need to implement the event loop API.https://docs.python.org/3/library/asyncio-eventloop.html#:~:text=The%20event%20loop%20is%20the,asyncio%20functions%2C%20such%20as%20asyncio.
This is the hard part which actually allows creation of futures and tasks. I'm not sure if the
await for
byte code that was already implemented in 3.4 has all the features we need, but it looks like we can get pretty far with the byte code we have already.The last piece of the puzzle is
select()
which allows us to wait on a socket while executing another co-routine.There's a good write-up here:
https://stackoverflow.com/questions/49005651/how-does-asyncio-actually-work
The text was updated successfully, but these errors were encountered: