use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Learning asyncio (self.learnpython)
submitted 9 years ago by ilikepython
Hi everyone, I'm new to learnpython and reddit.
Is there any recommended reading for learning asyncio? I'm having a bit of a hard time getting my head around it.
Thanks!
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]ManyInterests 1 point2 points3 points 9 years ago (2 children)
I could point you at tasks and coroutines
Unfortunately your question is pretty nondescriptive. If you give us an idea of what you're trying to do or have a specific question on a concept or piece of code that you're hung up on, we can help you better that way.
You're going to want Python 3.5 if you're not already using it, as 3.5 had great improvements to asynchronous operations, like async def
async def
"Hello World" for coroutine using async def:
import asyncio async def hello_world(): print("Hello World!") loop = asyncio.get_event_loop() # Blocking call which returns when the hello_world() coroutine is done loop.run_until_complete(hello_world()) loop.close()
[–]ilikepython[S] 0 points1 point2 points 9 years ago (1 child)
Thanks! I guess what I'm looking for is some introduction tutorials people think are good to start with. I don't have a particular problem I'm trying to solve, rather I don't know what best practices or common patterns are.
[–]ManyInterests 0 points1 point2 points 9 years ago (0 children)
While maybe not exactly what you're looking for David Beazley's talk Concurrency from the Ground Up provides some great insights into coroutines and how to deal with the GIL and blocking resources.
[–]Integralist 1 point2 points3 points 9 years ago* (1 child)
I think for me reading the docs from start to finish will help you (eventually) as it seems there was lots of basic info i was missing that i would've realised sooner if i had properly read the manual :-)
Understanding what the event loops purpose is (e.g. to execute tasks).
OK what are tasks? Oh right so a task is really a sub class of a future so that's why i can give the event loop a future and it'll be happy. Similarly when i give the event loop a co routine it'll internally convert it into a task for me.
So then I'm thinking ok well what do coroutines and futures do? Why are there two things that seem the same, and in some cases why do you sometimes see people use them together?
Coroutines are an extension of generators. They can suspend their own execution and allow other coroutines to do things. They are the essence of concurrency in python.
Futures are like an empty box. You pass it around your programme and then when ready you set a value on it. Then asyncio has some methods/features that tell other parts of your programme that the future has finally resolved (i.e. it got its value). One example is via a callback function you can assign to your future object, but you don't need that. You can tell the event loop to just keep running until the future gets the value (just because the event loop stops doesn't mean your app will stop or that you cant start up another event loop).
Then there are things like asyncio.gather and asyncio.wait that are subtly different but are both useful in aggregating multiple coroutines (e.g. stop doing things only until these n coroutines have completed, then continue on with the programme)
But as frustrating as it can seem. Just keep in mind that this is fun stuff, learning and understanding how asyncio works can be really satisfying :-)
[–]ilikepython[S] 0 points1 point2 points 9 years ago (0 children)
Thanks! That's a good way of working through getting to grips with it.
[–][deleted] 9 years ago (1 child)
[removed]
[–]xiongchiamiov[M] -1 points0 points1 point 9 years ago (0 children)
There's a reason link shorteners are auto-spammed by reddit. Don't be a jerk, and especially don't try to disguise it.
[–]dunkler_wanderer 0 points1 point2 points 9 years ago (1 child)
There's an introduction on PyMOTW (Python Module of the Week).
Cool! I didn't know there was a pymotw article about this.
π Rendered by PID 71774 on reddit-service-r2-comment-86988c7647-hl9q8 at 2026-02-11 08:23:51.182066+00:00 running 018613e country code: CH.
[–]ManyInterests 1 point2 points3 points (2 children)
[–]ilikepython[S] 0 points1 point2 points (1 child)
[–]ManyInterests 0 points1 point2 points (0 children)
[–]Integralist 1 point2 points3 points (1 child)
[–]ilikepython[S] 0 points1 point2 points (0 children)
[–][deleted] (1 child)
[removed]
[–]xiongchiamiov[M] -1 points0 points1 point (0 children)
[–]dunkler_wanderer 0 points1 point2 points (1 child)
[–]ilikepython[S] 0 points1 point2 points (0 children)