Skip to content

Commit 2641c05

Browse files
Use settrace by default for pdb.Pdb, but use monitoring for all
direct pdb usage
1 parent 47f1278 commit 2641c05

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

Lib/pdb.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,14 +303,15 @@ class Pdb(bdb.Bdb, cmd.Cmd):
303303
# Limit the maximum depth of chained exceptions, we should be handling cycles,
304304
# but in case there are recursions, we stop at 999.
305305
MAX_CHAINED_EXCEPTION_DEPTH = 999
306+
DEFAULT_BACKEND = 'settrace'
306307

307308
_file_mtime_table = {}
308309

309310
_last_pdb_instance = None
310311

311312
def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None,
312-
nosigint=False, readrc=True, mode=None):
313-
bdb.Bdb.__init__(self, skip=skip, backend='monitoring')
313+
nosigint=False, readrc=True, mode=None, backend=None):
314+
bdb.Bdb.__init__(self, skip=skip, backend=backend if backend else self.DEFAULT_BACKEND)
314315
cmd.Cmd.__init__(self, completekey, stdin, stdout)
315316
sys.audit("pdb.Pdb")
316317
if stdout:
@@ -2372,7 +2373,7 @@ def set_trace(*, header=None, commands=None):
23722373
if Pdb._last_pdb_instance is not None:
23732374
pdb = Pdb._last_pdb_instance
23742375
else:
2375-
pdb = Pdb(mode='inline')
2376+
pdb = Pdb(mode='inline', backend='monitoring')
23762377
if header is not None:
23772378
pdb.message(header)
23782379
pdb.set_trace(sys._getframe().f_back, commands=commands)
@@ -2487,7 +2488,7 @@ def main():
24872488
# modified by the script being debugged. It's a bad idea when it was
24882489
# changed by the user from the command line. There is a "restart" command
24892490
# which allows explicit specification of command line arguments.
2490-
pdb = Pdb(mode='cli')
2491+
pdb = Pdb(mode='cli', backend='monitoring')
24912492
pdb.rcLines.extend(opts.commands)
24922493
while True:
24932494
try:

Lib/test/test_pdb.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4069,7 +4069,13 @@ def test_multiline_completion(self):
40694069

40704070
def load_tests(loader, tests, pattern):
40714071
from test import test_pdb
4072-
tests.addTest(doctest.DocTestSuite(test_pdb))
4072+
def setUpPdbBackend(backend):
4073+
def setUp(test):
4074+
import pdb
4075+
pdb.Pdb.DEFAULT_BACKEND = backend
4076+
return setUp
4077+
tests.addTest(doctest.DocTestSuite(test_pdb, setUp=setUpPdbBackend('monitoring')))
4078+
tests.addTest(doctest.DocTestSuite(test_pdb, setUp=setUpPdbBackend('settrace')))
40734079
return tests
40744080

40754081

0 commit comments

Comments
 (0)