Skip to content

Commit c209a08

Browse files
committed
fix pdb can now set breakpoints on async functions
1 parent da1d468 commit c209a08

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

Lib/pdb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def find_first_executable_line(code):
130130
return code.co_firstlineno
131131

132132
def find_function(funcname, filename):
133-
cre = re.compile(r'def\s+%s(\s*\[.+\])?\s*[(]' % re.escape(funcname))
133+
cre = re.compile(r'(?:async\s+)?def\s+%s(\s*\[.+\])?\s*[(]' % re.escape(funcname))
134134
try:
135135
fp = tokenize.open(filename)
136136
except OSError:

Lib/test/test_pdb.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4587,6 +4587,26 @@ def bar():
45874587
]))
45884588
self.assertIn('break in bar', stdout)
45894589

4590+
def test_async_break(self):
4591+
script = """
4592+
import asyncio
4593+
4594+
async def main():
4595+
print(f"Hello")
4596+
await asyncio.sleep(1)
4597+
print(f"World!")
4598+
4599+
asyncio.run(main())
4600+
"""
4601+
commands = """
4602+
break main
4603+
continue
4604+
quit
4605+
"""
4606+
stdout, stderr = self.run_pdb_script(script, commands)
4607+
self.assertIn("Breakpoint 1 at", stdout)
4608+
self.assertIn("Hello", stdout)
4609+
45904610

45914611
class ChecklineTests(unittest.TestCase):
45924612
def setUp(self):

0 commit comments

Comments
 (0)