Skip to content

Commit 8955d78

Browse files
Use settrace by default for pdb.Pdb, but use monitoring for all
direct pdb usage
1 parent c9a92f6 commit 8955d78

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
@@ -307,14 +307,15 @@ class Pdb(bdb.Bdb, cmd.Cmd):
307307
# Limit the maximum depth of chained exceptions, we should be handling cycles,
308308
# but in case there are recursions, we stop at 999.
309309
MAX_CHAINED_EXCEPTION_DEPTH = 999
310+
DEFAULT_BACKEND = 'settrace'
310311

311312
_file_mtime_table = {}
312313

313314
_last_pdb_instance = None
314315

315316
def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None,
316-
nosigint=False, readrc=True, mode=None):
317-
bdb.Bdb.__init__(self, skip=skip, backend='monitoring')
317+
nosigint=False, readrc=True, mode=None, backend=None):
318+
bdb.Bdb.__init__(self, skip=skip, backend=backend if backend else self.DEFAULT_BACKEND)
318319
cmd.Cmd.__init__(self, completekey, stdin, stdout)
319320
sys.audit("pdb.Pdb")
320321
if stdout:
@@ -2376,7 +2377,7 @@ def set_trace(*, header=None, commands=None):
23762377
if Pdb._last_pdb_instance is not None:
23772378
pdb = Pdb._last_pdb_instance
23782379
else:
2379-
pdb = Pdb(mode='inline')
2380+
pdb = Pdb(mode='inline', backend='monitoring')
23802381
if header is not None:
23812382
pdb.message(header)
23822383
pdb.set_trace(sys._getframe().f_back, commands=commands)
@@ -2507,7 +2508,7 @@ def main():
25072508
# modified by the script being debugged. It's a bad idea when it was
25082509
# changed by the user from the command line. There is a "restart" command
25092510
# which allows explicit specification of command line arguments.
2510-
pdb = Pdb(mode='cli')
2511+
pdb = Pdb(mode='cli', backend='monitoring')
25112512
pdb.rcLines.extend(opts.commands)
25122513
while True:
25132514
try:

Lib/test/test_pdb.py

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

43404340
def load_tests(loader, tests, pattern):
43414341
from test import test_pdb
4342-
tests.addTest(doctest.DocTestSuite(test_pdb))
4342+
def setUpPdbBackend(backend):
4343+
def setUp(test):
4344+
import pdb
4345+
pdb.Pdb.DEFAULT_BACKEND = backend
4346+
return setUp
4347+
tests.addTest(doctest.DocTestSuite(test_pdb, setUp=setUpPdbBackend('monitoring')))
4348+
tests.addTest(doctest.DocTestSuite(test_pdb, setUp=setUpPdbBackend('settrace')))
43434349
return tests
43444350

43454351

0 commit comments

Comments
 (0)