[Tutor] What exactly does "await" do? (David)(Mats Wichmann)(Alan Gauld)

ThreeBlindQuarks threesomequarks at proton.me
Sat Feb 18 15:45:17 EST 2023


I think David has expressed some of my own sentiments better. 

I too found the discussion to be a tad above most of the questions submitted here as quite general about an advanced topic. Most python programmers have never had a reason to use things like asyncio. For some things it is a luxury not needed on our faster computers. In other cases, the modules or packages we use hide it under the rug and we do not have to worry much about how.

Yes, it is well worth learning. But perhaps not here in great detail or perhaps using more focused questions on an easily understood minimal example.

The question is why the person asking wants to know? What local resources have they exhausted without getting an answer? Would they benefit from an individual tutor who knows and can show it in person, not this semi-public forum?

I would add to David's list of questions, the fact that somebody out there has been known to jump in with fairly abstract or difficult questions and then sat back and watched the debate they cause. One individual seems to then use the discussion for purposes like writing books and getting free consulting of a sort. This may not be the case today, but if the volunteers here get diverted into overly technical discussions, we may simply drive away the main users of this group who simply want a little help on fairly basic items and are stuck.

So the added question is whether someone is just asking to see what the responses will be or really has a specific reason they need to know.

As an aside, I have had occasion to read really old code in Python, and other languages, and been mystified by some of the code. I had to consult books and other resources to find out about some language feature that was introduced in say version 2.3 and then replaced in version 2.5 but continued to work for a few more releases. So the mysterious code often turned out to be a preliminary method that no longer has much reason to be used. Lots of asyncio is like that. Some has been done in whatever way people could manage and now there may be a better way albeit maybe an incompatible way in some cases.

My personal path to learning about asyncio was to pause looking at in in Python and switch to (re)learn JavaScript and Node.JS (close to the same language, not quite) which was designed early on to do things in various asynchronous ways and has been modified in some ways to use newer techniques such as promises. Once I sort of understood that, in a language where using such methods is way more common, I went back to studying some of the Python implementations. 

This is not a path for many other people, and what David wrote is what many do. Instead of deep study, you work on finding what you hope are similar enough recipes/examples and then trying to adjust the framework for your own needs. That is not at all easy to do in this case as every few releases of Python add new functionality or make older ways get deprecated. But as long as you are writing for a project that will not be using older versions, fine.

There are many things to watch out for or to use. In many cases, you need to make sure some functions you use (or generator objects) have been created with or use the "async" keyword properly and in other cases, that they have NOT. There are lots of NEW aspects to the language such as using "async for" instead of a regular for loop or "async with" and others and that includes inside things like list comprehensions. Some of that extends into a new set of dunder methods you might need to be aware of or use. So an object having a __iter__ method in synchronous mode would need a __aiter__ method as one part of being used asynchronously. 

There are lots of such changes and details and lots of people have created all kinds of modules that hide pesky details if you use their module to perform some tasks where the underlying asynchronous nature is fairly well hidden and you can concentrate on getting THAT task done. 

If anyone wishes to continue, may I suggest the conversation be moved anywhere else, such as a Python board not intended for beginners?

I will not await a response as I am asynchronously moving on to other things I constantly juggle in my life and cannot easily do them all at once.

Quark






Sent with Proton Mail secure email.

------- Original Message -------
On Saturday, February 18th, 2023 at 6:02 AM, David <bouncingcats at gmail.com> wrote:


> On Sat, 18 Feb 2023 at 20:08, Alphonsus phonokoye at gmail.com wrote:
> 
> 
> Hi Alphonsus,
> 
> You wrote:
> 
> > The low level stuff involves the asyncio event loop, Future objects and
> > some concept called a Transport. All of these may not be used frequently
> > but are important for greater control over an asyncio program. These
> > parts of asyncio are probably the most tricky parts. It is important to
> > understand these parts though, so as to make better programming
> > decisions. I also do not understand the low level approach to IO in
> > python. Can I get references that teach these?
> 
> 
> I will answer regarding "low level stuff":
> 
> I am writing here as just one individual person who sometimes asks or
> answers questions here. In my opinion, your questions have now moved on to
> advanced topics. It is possible that other people here might answer them,
> but it is my understanding that discussing advanced topics is not really
> the purpose of this list.
> 
> Everything I know about asyncio has come from the references that I shared
> with you in a previous message. So, I myself cannot give you any more
> information.
> 
> For myself, when I needed to use asyncio, I found those references and read
> them, and then I used that knowledge to write some code using coroutines.
> That code runs on an STM32 microcontroller and calls the MicroPython
> implementation of asyncio. It handles the realtime event loop, which
> manages coroutines for the user interface, A/D conversions, data output.
> That code works successfully and it does everything that I need.
> 
> So, my personal experience has been that I have been able to write useful
> asyncio code in Python without knowing anything about the advanced aspects
> of it. Have you tried to write any code using asyncio?
> 
> May I also ask, why do you think that you need to know the answers to the
> questions that you are asking?
> 
> Are you writing code? What is the project?
> Are you writing an essay? Who will read it?
> Are you applying for a job?
> Are you creating an online course?
> Are you studying a course?
> 
> As I already said, someone else might answer your question in a different
> way, because that is how things happen here. We all have different approaches
> to answering questions.
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor


More information about the Tutor mailing list