Closed
Description
I was experimenting with the example provided in the documentation and I noticed a strange behavior when using asyncio.
This is an example script:
import asyncio
import greenlet
def syncg():
print("before g2")
print("g2 result", syncg2.switch())
print("after g2")
def g2sync():
print("in g2")
return 42
syncg1 = greenlet.greenlet(syncg)
syncg2 = greenlet.greenlet(g2sync)
print("sync version")
print("sync result", syncg1.switch())
async def asyncg():
print("before g2")
print("g2 result", asyncg2.switch())
print("after g2")
def g2async():
print("in g2")
return 42
asyncg1 = greenlet.greenlet(asyncg)
asyncg2 = greenlet.greenlet(g2async)
print("asyncio version")
print("asyncio result", asyncio.run(asyncg1.switch()))
My understanding is that these two cases should be equal and print the lines "before g2"
and "in g2"
and return 42.
The async version resumes the execution of asyncg1 after asyncg2 exits instead.
This is the output:
sync version
before g2
in g2
sync result 42
asyncio version
before g2
in g2
g2 result 42
after g2
asyncio result None
python: 3.8.3
greenlet: 0.4.16
I tested on windows but the same behavior happen on linux
Metadata
Metadata
Assignees
Labels
No labels