Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8522897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:15:27+00:00 2026-06-11T07:15:27+00:00

As a newbie to Python, I’m finding yields and generators and async functions extremely

  • 0

As a newbie to Python, I’m finding yields and generators and async functions extremely overwhelming (I’ve read all the SO questions on the topics and several other various references – still having a hard time connecting all the pieces). I’m used to the descriptive syntax of Objective-C, where everything just tells you what it’s doing, rather than trying to connect all the pieces of distinct keywords that you don’t know really know how they might work together.

I really liked Python because it was so easy to pick up – for basic things at least. But for more advanced things, the code just doesn’t speak to you. It doesn’t tell you what it’s doing. (Ok maybe I’m just a little frustrated and inexperienced.)

Anyway, I want to make the following function fully async:

@ndb.tasklet
def get_new_statues(friends):
    status_list = list()
    for friend_dic in friends:
        lastStatusDate = #some date
        userKey = #some key
        query = ndb.gql('SELECT * FROM Statuses WHERE ANCESTOR IS :1 AND date > :2', userKey, lastStatusDate)
        qit = query.iter()
        while (yield qit.has_next_async()):
            status = qit.next()
            status_list.append(status.to_dict())
    raise ndb.Return(status_list)

I was a little impressed with myself when I wrote this, and was excited that I was able to convert all my code to async in just a couple hours. But I’m being told that the function above isn’t async at all. But then in another question I’m being told that yes, what I’m doing is correct.

So what exactly is going on? Does the yield statement here make my code synchronous? How would I modify this to make it async?

(The questions I’ve asked seem all similar, but the problem is I’m getting more code back as answers rather than an explanation. I’m a human looking for words to understand that can help me make sense of code, not a machine looking for more code to help me understand more code. Everyone is just telling me how or what, no one is telling me why.)

Addendum: I guess the line that’s throwing me off the most is: while (yield qit.has_next_async()): As a human reader, I read the words yield, which in your typical usage of the word means “if necessary let something else do something else” and I see the word async, which well means async. So I figured yield + async = magical formula for an asynchronous method, but apparently that’s not the case?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T07:15:29+00:00Added an answer on June 11, 2026 at 7:15 am

    Sounds like you don’t understand what yield does.

    While this may not be entirely accurate, you can generally think of “yield” like “return”, except when you call this function again, it continues running from where it last yielded, rather than the beginning of the function.

    Since qit.has_next_async() is asynchronous, this function is asynchronous. Every time you call this function, it’ll return the value of qit.has_next_function(), and it’ll get the next entity. When it’s done it’ll raise an exception with the result.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Now following my series of python newbie questions and based on another question .
First of all I'm a python newbie. I'm playing with Django and I'm trying
Newbie Python question. I have a class that inherits from several classes, and some
I am a newbie to python and just learning things as i do my
I am newbie in Python and I need help: I have a file with
As a newbie to Python, and mainly having a background of writing scripts for
I'm newbie in Python. I can't understand why this code does not work: reOptions
I'm a python newbie and starting out with using the Bottle web framework on
I'm newbie for python, I'm having task so I need to scan wifi and
I am a newbie in Python. I try to work with server using Thrift

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.