New "Cannot reuse already awaited compiled_coroutine" issue with reproducible code
See original GitHub issueUsing 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:
- Created 5 years ago
- Comments:25 (18 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@levesquejf sorry to distracted, but I will get to it
Released as 0.6.5