Skip to content

Commit

Permalink
bpo-36250: ignore ValueError from signal in non-main thread (pythonGH…
Browse files Browse the repository at this point in the history
…-12251)

Authored-By: blueyed <github@thequod.de>
  • Loading branch information
blueyed authored and zware committed Sep 9, 2019
1 parent 19052a1 commit 8d64bfa
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,12 @@ def preloop(self):
def interaction(self, frame, traceback):
# Restore the previous signal handler at the Pdb prompt.
if Pdb._previous_sigint_handler:
signal.signal(signal.SIGINT, Pdb._previous_sigint_handler)
Pdb._previous_sigint_handler = None
try:
signal.signal(signal.SIGINT, Pdb._previous_sigint_handler)
except ValueError: # ValueError: signal only works in main thread
pass
else:
Pdb._previous_sigint_handler = None
if self.setup(frame, traceback):
# no interaction desired at this time (happens if .pdbrc contains
# a command like "continue")
Expand Down
29 changes: 29 additions & 0 deletions Lib/test/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1333,6 +1333,35 @@ def start_pdb():
self.assertNotIn('Error', stdout.decode(),
"Got an error running test script under PDB")

def test_issue36250(self):

with open(support.TESTFN, 'wb') as f:
f.write(textwrap.dedent("""
import threading
import pdb
evt = threading.Event()
def start_pdb():
evt.wait()
pdb.Pdb(readrc=False).set_trace()
t = threading.Thread(target=start_pdb)
t.start()
pdb.Pdb(readrc=False).set_trace()
evt.set()
t.join()""").encode('ascii'))
cmd = [sys.executable, '-u', support.TESTFN]
proc = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
self.addCleanup(proc.stdout.close)
stdout, stderr = proc.communicate(b'cont\ncont\n')
self.assertNotIn('Error', stdout.decode(),
"Got an error running test script under PDB")

def test_issue16180(self):
# A syntax error in the debuggee.
script = "def f: pass\n"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Ignore ``ValueError`` from ``signal`` with ``interaction`` in non-main
thread.

0 comments on commit 8d64bfa

Please sign in to comment.