0

Let's say we have the following functions:

async def x1():
    print("inside x1")

async def x2():
    print("inside x2")

async def main():
    await x1()
    x2()
    await asyncio.sleep(5) 

loop = asyncio.get_event_loop()
loop.run_until_complete(main())

I will get a warning of the following:

RuntimeWarning: coroutine 'x2' was never awaited

Are there any way to make Python raises an error instead of just printing a warning?

Ahmed
  • 2,825
  • 1
  • 25
  • 39
  • 1
    i don't see where this error could possibly be raised. The warning refers to a thing that didn't happen - "x was never awaited" - so there is no specific line of code where an exception occurred. – Paul Cornelius Jul 18 '20 at 17:49
  • I understand that. Forgetting adding await in a front of awaitable function that meant to be called will result in a code bug. My question is how to detect code bugs that are related to forgetting the keyword `await` – Ahmed Jul 19 '20 at 18:23
  • https://stackoverflow.com/questions/5644836/in-python-how-does-one-catch-warnings-as-if-they-were-exceptions – Dhiraj Dhule Jul 24 '20 at 13:28

0 Answers0