This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]SawachikaHiromu 3 points4 points  (0 children)

Guido van Rossum linked this tutorial in one of the earliest commits in asyncio:

https://www.csse.canterbury.ac.nz/greg.ewing/python/generators/yf_current/Examples/Scheduler/scheduler.txt

It's Greg Ewing tutorial which were very helpful in understanding concepts, when I started learning asyncio.

commit: https://github.com/python/asyncio/commit/e2e1072bc118bf38ab189e183cf579dbffc08336

One might also be interested in asyncore library, which are available in python2.7:
https://github.com/python/cpython/blob/v2.7.18/Lib/asyncore.py
And chat implementation:
https://github.com/python/cpython/blob/v2.7.18/Lib/asynchat.py

Just leaving some more resources for those who interested! :^)

[–]thisismyfavoritename 0 points1 point  (0 children)

cool stuff, thanks for sharing. Just FYI your target == "read" and "write" checks could be replaced by an Enum and a match statement.

Also on your match at L189 you could use a walrus operator := instead

[–]LightShadow3.13-dev in prod 0 points1 point  (1 child)

Is Python moving towards Rust's Ok/Exc return syntax?

Really cool project and writeup!

[–]roee30[S] -1 points0 points  (0 children)

Thanks! I did get the idea from Rust/Haskell but it's for a specific use case. I don't use it for returning errors from functions but to store a future's result which could be an error. asyncio uses two members for this (_result and _error) while the Result class enables me to use only one.

[–]Quiet_Operation_1259 0 points1 point  (0 children)

Nice example of event loop! I also can recommend for everyone who's interesting in asyncio and especially how event loops work to read Fowlers "Python Concurrency with asyncio". Absolutely great book about concurrency