File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1031,8 +1031,15 @@ def do_continue(self, arg):
10311031 Continue execution, only stop when a breakpoint is encountered.
10321032 """
10331033 if not self .nosigint :
1034- self ._previous_sigint_handler = \
1035- signal .signal (signal .SIGINT , self .sigint_handler )
1034+ try :
1035+ self ._previous_sigint_handler = \
1036+ signal .signal (signal .SIGINT , self .sigint_handler )
1037+ except ValueError :
1038+ # ValueError happens when do_continue() is invoked from
1039+ # a non-main thread in which case we just continue without
1040+ # SIGINT set. Would printing a message here (once) make
1041+ # sense?
1042+ pass
10361043 self .set_continue ()
10371044 return 1
10381045 do_c = do_cont = do_continue
Original file line number Diff line number Diff line change @@ -667,6 +667,33 @@ def bar():
667667 any ('main.py(5)foo()->None' in l for l in stdout .splitlines ()),
668668 'Fail to step into the caller after a return' )
669669
670+ def test_issue13210 (self ):
671+ # invoking "continue" on a non-main thread triggered an exception
672+ # inside signal.signal
673+
674+ with open (support .TESTFN , 'wb' ) as f :
675+ f .write (textwrap .dedent ("""
676+ import threading
677+ import pdb
678+
679+ def start_pdb():
680+ pdb.Pdb().set_trace()
681+ x = 1
682+ y = 1
683+
684+ t = threading.Thread(target=start_pdb)
685+ t.start()""" ).encode ('ascii' ))
686+ cmd = [sys .executable , '-u' , support .TESTFN ]
687+ proc = subprocess .Popen (cmd ,
688+ stdout = subprocess .PIPE ,
689+ stdin = subprocess .PIPE ,
690+ stderr = subprocess .STDOUT ,
691+ )
692+ self .addCleanup (proc .stdout .close )
693+ stdout , stderr = proc .communicate (b'cont\n ' )
694+ self .assertNotIn ('Error' , stdout .decode (),
695+ "Got an error running test script under PDB" )
696+
670697 def tearDown (self ):
671698 support .unlink (support .TESTFN )
672699
Original file line number Diff line number Diff line change @@ -104,6 +104,9 @@ Core and Builtins
104104Library
105105-------
106106
107+ - Issue #13120: Allow to call pdb.set_trace() from thread.
108+ Patch by Ilya Sandler.
109+
107110- Issue #16585: Make CJK encoders support error handlers that return bytes per
108111 PEP 383.
109112
You can’t perform that action at this time.
0 commit comments