Await an async function in Python debugger

Here a modified version of what I posted at https://stackoverflow.com/a/67847257/893857 since it also solves this problem.

I found a solution using nest_asyncio. If one has the following async example script:

import asyncio
import nest_asyncio


async def bar(x):
    return x + 1

async def foo():
    import ipdb; ipdb.set_trace()


if __name__=="__main__":
    loop = asyncio.get_event_loop()
    nest_asyncio.apply(loop)
    loop.run_until_complete(foo())

One can then do:

      8 async def foo():
----> 9     import ipdb; ipdb.set_trace()
     10 

ipdb> loop = asyncio.get_event_loop()
ipdb> loop.run_until_complete(bar(1))
2

Admittedly it is a bit more tedious then await bar(1) but it gets the job done. Hopefully a more elegant solution will come up in the future.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)