msg145040 - (view) |
Author: Ben Bass (bpb) |
Date: 2011-10-06 21:17 |
The new SIGINT behaviour of pdb.Pdb prevents use of pdb within a non-main thread without explicitly setting nosigint=True. Specifically the 'continue' command causes a traceback as follows: {{{ ... File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/pdb.py", line 959, in do_continue signal.signal(signal.SIGINT, self.sigint_handler) ValueError: signal only works in main thread }}} Since the new behaviour seems to be to gain an enhancement rather than anything fundamentally necessary to pdb, wouldn't it be better if the default was reversed, so the same code would work identically on Python 3.1 (and potentially earlier, i.e. Python2) and Python 3.2? At the moment in my codebase (rpcpdb) I'm using inspect.getargspec sniffing for nosigint on pdb.Pdb.__init__ to determine whether to include a nosigint=True parameter, which clearly isn't ideal! |
|
|
msg148439 - (view) |
Author: Ilya Sandler (isandler) |
Date: 2011-11-27 03:10 |
I confirm the bug. But I don't think disabling Ctrl-C (SIGINT) handling by default is a good idea. Proper Ctrl-C support seems like a fundamental feature for a command line debugger. However, I think the bug is easily fixable w/o changing SIGINT handling. Basically, just put try/except around signal.signal, catch the ValueError and proceed. Would this approach solve your problem? Patch attached. PS. and here is a small program demonstrating the bug (just run it and execute "c" command at pdb prompt) import threading import pdb def start_pdb(): pdb.Pdb().set_trace() x = 1 y = 1 t = threading.Thread( target=start_pdb) t.start() |
|
|
msg148457 - (view) |
Author: Georg Brandl (georg.brandl) *  |
Date: 2011-11-27 20:09 |
Patch seems fine to me. |
|
|
msg148463 - (view) |
Author: Meador Inge (meador.inge) *  |
Date: 2011-11-27 23:26 |
Normally a test case is needed. I tried the following: diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -595,6 +595,25 @@ def test_pdb_run_with_code_object(): (Pdb) continue """ +def test_pdb_continue_in_thread(): + """Testing the ability to continue from a non-main thread. + + >>> import threading + >>> + >>> def start_pdb(): + ... import pdb + ... pdb.Pdb().set_trace() + ... x = 1 + ... y = 1 + ... + + >>> with PdbTestInput(['continue']): + ... t = threading.Thread(target=start_pdb) + ... t.start() + > <doctest test.test_pdb.test_pdb_continue_in_thread[1]>(4)start_pdb() + -> x = 1 + (Pdb) continue +""" but 'doctests' doesn't seem to play nicely with threading. The pdb testsuite fails with: [meadori@motherbrain cpython]$ ./python -m test test_pdb [1/1] test_pdb ********************************************************************** File "/home/meadori/code/python/cpython/Lib/test/test_pdb.py", line 610, in test.test_pdb.test_pdb_continue_in_thread Failed example: with PdbTestInput(['continue']): t = threading.Thread(target=start_pdb) t.start() Expected: > <doctest test.test_pdb.test_pdb_continue_in_thread[1]>(4)start_pdb() -> x = 1 (Pdb) continue Got nothing ********************************************************************** File "/home/meadori/code/python/cpython/Lib/test/test_pdb.py", line 34, in test.test_pdb.test_pdb_displayhook Failed example: def test_function(foo, bar): import pdb; pdb.Pdb(nosigint=True).set_trace() pass Expected nothing Got: > <doctest test.test_pdb.test_pdb_continue_in_thread[1]>(4)start_pdb() Exception in thread Thread-1: It looks like the output is going to the wrong test. Anyone else have test ideas? If not, then I guess it is OK to commit as is. |
|
|
msg148466 - (view) |
Author: Ilya Sandler (isandler) |
Date: 2011-11-28 04:08 |
I think stuff like this can only be tested out-of-process. So I added an out-of-process test to test_pdb.py. The test passes with the fixed pdb.py. (and fails with the original one). Patch for the test attached. |
|
|
msg148705 - (view) |
Author: Meador Inge (meador.inge) *  |
Date: 2011-12-01 05:26 |
Ilya, I agree. Thanks for the test patch. These two patches look OK to me. Georg OK with you? |
|
|
msg176806 - (view) |
Author: (icemac) |
Date: 2012-12-02 19:47 |
This bug bites me when developing with Pyramid using Python 3.2. I'd like to get it solved generally as the patch works for me (Python 3.2.3)). What needs to be done to get this patch into the version control system? |
|
|
msg176822 - (view) |
Author: Andrew Svetlov (asvetlov) *  |
Date: 2012-12-03 00:34 |
Uploaded updated cumulative patch. Can we apply the patch to 3.2 or at least to 3.3? I see nothing wrong with it, but I'm ok with pushing to 3.4 only if we want to be extra careful. |
|
|
msg176931 - (view) |
Author: Roundup Robot (python-dev)  |
Date: 2012-12-04 19:11 |
New changeset 708586792eec by Andrew Svetlov in branch '3.2': Issue #13120: Allow to call pdb.set_trace() from thread. http://hg.python.org/cpython/rev/708586792eec New changeset 678dba60c12d by Andrew Svetlov in branch '3.3': Merge issue #13120: Allow to call pdb.set_trace() from thread. http://hg.python.org/cpython/rev/678dba60c12d New changeset 4006c4ca0c1f by Andrew Svetlov in branch 'default': Merge issue #13120: Allow to call pdb.set_trace() from thread. http://hg.python.org/cpython/rev/4006c4ca0c1f |
|
|
msg176932 - (view) |
Author: Andrew Svetlov (asvetlov) *  |
Date: 2012-12-04 19:14 |
Fixed. Thanks. |
|
|
msg176977 - (view) |
Author: Stefan Krah (skrah) *  |
Date: 2012-12-05 11:56 |
I think this commit broke the --without-threads buildbot: http://buildbot.python.org/all/builders/AMD64%20Fedora%20without%20threads%203.x/builds/3581/steps/test/logs/stdio |
|
|
msg176979 - (view) |
Author: Andrew Svetlov (asvetlov) *  |
Date: 2012-12-05 12:41 |
Will take a look. |
|
|
msg176980 - (view) |
Author: Roundup Robot (python-dev)  |
Date: 2012-12-05 13:07 |
New changeset 26056f8a0afe by Andrew Svetlov in branch '3.2': Skip pdb test for #13120 if threading is not available. http://hg.python.org/cpython/rev/26056f8a0afe New changeset 328a8824c1a7 by Andrew Svetlov in branch '3.3': Merge: skip pdb test for #13120 if threading is not available. http://hg.python.org/cpython/rev/328a8824c1a7 New changeset 4cb84c0fbee2 by Andrew Svetlov in branch 'default': Merge: skip pdb test for #13120 if threading is not available. http://hg.python.org/cpython/rev/4cb84c0fbee2 |
|
|
msg176983 - (view) |
Author: Andrew Svetlov (asvetlov) *  |
Date: 2012-12-05 13:43 |
Failed test is skipped if there are no threads. Thanks for report, Stefan! |
|
|
msg337573 - (view) |
Author: daniel hahler (blueyed) * |
Date: 2019-03-09 15:07 |
Just for reference: there is a similar issue with `interaction`: https://bugs.python.org/issue36250. |
|
|
msg339306 - (view) |
Author: miss-islington (miss-islington) |
Date: 2019-04-01 21:59 |
New changeset 9139f926a8d8e5b71830cb7e10b0807836b5e9a4 by Miss Islington (bot) (Daniel Hahler) in branch 'master': bpo-13120: fix typo with test_issue13120() method name (GH-12250) https://github.com/python/cpython/commit/9139f926a8d8e5b71830cb7e10b0807836b5e9a4 |
|
|
msg339320 - (view) |
Author: miss-islington (miss-islington) |
Date: 2019-04-02 08:17 |
New changeset 5ca4fe04784fa278c319a3764c9a755f49cc0944 by Miss Islington (bot) in branch '3.7': bpo-13120: fix typo with test_issue13120() method name (GH-12250) https://github.com/python/cpython/commit/5ca4fe04784fa278c319a3764c9a755f49cc0944 |
|
|