cocolato · GitHub

Bug report

Bug description:

I found that while debugging with pdb you currently cannot set a breakpoint on an async function. Reproducer:

import asyncio
async def main():
    print(f"Hello")
    await asyncio.sleep(1)
    print(f"World!")
asyncio.run(main())

If you run pdb and try to set a breakpoint on main you get:

λ › ./python -m pdb main.py
> /cpython/main.py(1)<module>()
-> import asyncio
(Pdb) break main
*** The specified object 'main' is not a function or was not found along sys.path.
(Pdb) quit

This happens because the regular expression used by find_function does not match async functions:

def find_function(funcname, filename):
cre = re.compile(r'def\s+%s(\s*\[.+\])?\s*[(]' % re.escape(funcname))

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Read the original on github.com ↗