Skip to content

Support pdb breakpoints on async functions #141982

@cocolato

Description

@cocolato

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:

cpython/Lib/pdb.py

Lines 132 to 133 in 2ff8608

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions