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 pitrou
Recipients giampaolo.rodola, pitrou, vstinner, yselivanov
Date 2017-11-06.17:24:09
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1509989049.58.0.213398074469.issue31960@psf.upfronthosting.co.za>
In-reply-to
Content
If you await a Future with another loop than a loop at instance creation (this is trivial to do accidentally when using threads), asyncio raises a RuntimeError.  But if you use another part of the Future API, such as add_done_callback(), the situation isn't detected.

For example, this snippet will run indefinitely:

import asyncio
import threading


fut = asyncio.Future()

async def coro(loop):
    fut.add_done_callback(lambda _: loop.stop())
    loop.call_later(1, fut.set_result, None)
    while True:
        await asyncio.sleep(100000)

def run():
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)
    loop.run_until_complete(coro(loop))
    loop.close()


t = threading.Thread(target=run)
t.start()
t.join()
History
Date User Action Args
2017-11-06 17:24:09pitrousetrecipients: + pitrou, vstinner, giampaolo.rodola, yselivanov
2017-11-06 17:24:09pitrousetmessageid: <1509989049.58.0.213398074469.issue31960@psf.upfronthosting.co.za>
2017-11-06 17:24:09pitroulinkissue31960 messages
2017-11-06 17:24:09pitroucreate