summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Hahler <github@thequod.de>2019-09-09 10:45:58 (GMT)
committerZachary Ware <zachary.ware@gmail.com>2019-09-09 10:45:58 (GMT)
commit8d64bfafdffd9f866bb6ac2e5b4c4bdfcb16aea0 (patch)
tree43faa4a0d28d0647d05ac7443c74e1f3d968e1a5
parent19052a11314e7be7ba003fd6cdbb5400a5d77d96 (diff)
downloadcpython-8d64bfafdffd9f866bb6ac2e5b4c4bdfcb16aea0.zip
cpython-8d64bfafdffd9f866bb6ac2e5b4c4bdfcb16aea0.tar.gz
cpython-8d64bfafdffd9f866bb6ac2e5b4c4bdfcb16aea0.tar.bz2
bpo-36250: ignore ValueError from signal in non-main thread (GH-12251)
Authored-By: blueyed <github@thequod.de>
-rwxr-xr-xLib/pdb.py8
-rw-r--r--Lib/test/test_pdb.py29
-rw-r--r--Misc/NEWS.d/next/Library/2019-03-09-16-04-12.bpo-36250.tSK4N1.rst2
3 files changed, 37 insertions, 2 deletions
diff --git a/Lib/pdb.py b/Lib/pdb.py
index 69fd8bd..8c1c961 100755
--- a/Lib/pdb.py
+++ b/Lib/pdb.py
@@ -340,8 +340,12 @@ class Pdb(bdb.Bdb, cmd.Cmd):
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")
diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py
index 646bdb1..fcb7e4e 100644
--- a/Lib/test/test_pdb.py
+++ b/Lib/test/test_pdb.py
@@ -1333,6 +1333,35 @@ class PdbTestCase(unittest.TestCase):
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"
diff --git a/Misc/NEWS.d/next/Library/2019-03-09-16-04-12.bpo-36250.tSK4N1.rst b/Misc/NEWS.d/next/Library/2019-03-09-16-04-12.bpo-36250.tSK4N1.rst
new file mode 100644
index 0000000..8d9fbcb
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2019-03-09-16-04-12.bpo-36250.tSK4N1.rst
@@ -0,0 +1,2 @@
+Ignore ``ValueError`` from ``signal`` with ``interaction`` in non-main
+thread.