Because Python generators don't do anything when you call the function. They only execute code when you call next (or send) on them (or when you do something that calls their next - like iterating on them with a for loop or making a list out of them)
In[1]:defsingle_io():...:print('starting the IO')...:yield...:print('processing the IO result')In[2]:coroutine=single_io()In[3]:# The coroutine did not actually start yet
In[4]:# It will only start here:
In[5]:next(coroutine)startingtheIOIn[6]:
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Because Python generators don't do anything when you call the function. They only execute code when you call
next
(orsend
) on them (or when you do something that calls theirnext
- like iterating on them with afor
loop or making alist
out of them)