question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New "Cannot reuse already awaited compiled_coroutine" issue with reproducible code

See original GitHub issue

Using 0.6.0.6 with Python 3.7.2, I have been able to reproduce the RuntimeError: cannot reuse already awaited compiled_coroutine. Similar issue as #165.

The following code is used to reproduce the issue. Complete instructions with Dockerfiles, available at https://github.com/levesquejf/nuitka-asyncio-bug.

import asyncio

from concurrent.futures import CancelledError
from contextlib import asynccontextmanager


@asynccontextmanager
async def async_context():
    ctx = Obj()
    yield ctx


class Obj:
    async def fail_now(self, *args, **kwargs):
        raise RuntimeError('Ok, time to crash!')


class Obj2:
    async def run(self):
        for _ in range(0, 2):
            async with async_context() as ctx:
                reader_task = asyncio.ensure_future(self.reader(ctx))
                writer_task = asyncio.ensure_future(self.writer(ctx))
                done, pending = await asyncio.wait(
                    [reader_task, writer_task],
                    return_when=asyncio.FIRST_COMPLETED,
                )

                for task in pending:
                    task.cancel()
                    try:
                        await task
                    except CancelledError:
                        print('Cancelled')
                        pass
                for task in done:
                    try:
                        await task
                    except Exception as e:
                        print(f'Exception catched: {e}', flush=True)

    async def reader(self, my_obj):
        await asyncio.sleep(1)
        await my_obj.fail_now(self)

    async def writer(self, my_obj):
        await asyncio.sleep(2)
        await my_obj.fail_now(self)


def main():
    loop = asyncio.get_event_loop()
    my_obj = Obj2()
    loop.run_until_complete(my_obj.run())


if __name__ == '__main__':
    main()

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:25 (18 by maintainers)

github_iconTop GitHub Comments

1reaction
kayhayencommented, Jan 23, 2019

@levesquejf sorry to distracted, but I will get to it

0reactions
kayhayencommented, Jul 27, 2019

Released as 0.6.5

Read more comments on GitHub >

github_iconTop Results From Across the Web

asyncio - await coroutine more than once (periodic tasks)
It seems you are confusing async functions (coroutine functions) with coroutines - values that these async functions produce.
Read more >
awaiting on coroutine more than once should be an error
I'll duplicate the fixed code: async def coroutine(): return 123 coro ... Fine with me to have "coroutine was already awaited on".
Read more >
Python Asyncio Part 2 – Awaitables, Tasks, and Futures
Any object of class asyncio. Future which when awaited causes the current Task to be paused until a specific condition occurs (see next...
Read more >
Async IO in Python: A Complete Walkthrough
async / await : two new Python keywords that are used to define ... Asynchronous code, through the mechanism above, facilitates concurrent execution....
Read more >
Build Your Own Async - YouTube
Screencast based on a workshop originally presented at PyCon India, Chennai, October 14, 2019. Code samples at: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found