This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Dima.Tisnek
Recipients Dima.Tisnek, asvetlov, yselivanov
Date 2019-06-06.10:29:59
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1559816999.36.0.898434753785.issue37172@roundup.psfhosted.org>
In-reply-to
Content
Let's start with correct code:


import asyncio


async def writer():
    await asyncio.sleep(1)
    g1.set_result(41)

async def reader():
    await g1

async def test():
    global g1
    g1 = asyncio.Future()
    await asyncio.gather(reader(), writer())

asyncio.run(test())


No error, as expected.

Now let's mess it up a bit:


import asyncio

g1 = asyncio.Future()


async def writer():
    await asyncio.sleep(1)
    g1.set_result(41)

async def reader():
    await g1

async def test():
    await asyncio.gather(reader(), writer())

asyncio.run(test())


Fails with RuntimeError ... attached to a different loop

The error makes sense, although it's sad that I can't create global futures / there was no even loop when Future was creates, it was not a *different* event loop / maybe I wish .run() didn't force a new event loop?

A nit (IMO), but I can live with it.

Let's mess the code up a bit more:


import asyncio

g1 = asyncio.Future()


async def writer():
    await asyncio.sleep(1)
    g1.set_result(41)

async def reader():
    await g1

async def test():
    await asyncio.gather(reader(), reader(), writer())

asyncio.run(test())


RuntimeError: await wasn't used with future

What?
That's really confusing!
The only difference is that there are now 2 readers running in parallel.

The actual exception comes from asyncio.Future.__await__ after a yield.
I'm not sure how to fix this...
History
Date User Action Args
2019-06-06 10:29:59Dima.Tisneksetrecipients: + Dima.Tisnek, asvetlov, yselivanov
2019-06-06 10:29:59Dima.Tisneksetmessageid: <1559816999.36.0.898434753785.issue37172@roundup.psfhosted.org>
2019-06-06 10:29:59Dima.Tisneklinkissue37172 messages
2019-06-06 10:29:59Dima.Tisnekcreate