Unable to launch pdb from subprocess reader thread

Issue #3003 resolved
Andrew Lawrence created an issue

Discovered on the winmultiprocessing branch.

While attempting to debug SpawnCmdLineTest.test_basic_script I placed a call to pdb inside the readerthread in subprocess.py

def _readerthread(self, fh, buffer):
            import pdb; pdb.set_trace()
            buffer.append(fh.read())
            fh.close()

When running the test both reader threads used to communicate with the subprocess raised the following exception:

Exception in thread Thread-2:
Traceback (most recent call last):
  File "C:\pypy\lib-python\3\threading.py", line 916, in _bootstrap_inner
    self.run()
  File "C:\pypy\lib-python\3\threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "C:\pypy\lib-python\3\subprocess.py", line 1083, in _readerthread
    buffer.append(fh.read())
  File "C:\pypy\lib-python\3\bdb.py", line 48, in trace_dispatch
    return self.dispatch_line(frame)
  File "C:\pypy\lib-python\3\bdb.py", line 66, in dispatch_line
    self.user_line(frame)
  File "C:\pypy\lib-python\3\pdb.py", line 261, in user_line
    self.interaction(frame, None)
  File "C:\pypy\lib-python\3\pdb.py", line 344, in interaction
    signal.signal(signal.SIGINT, Pdb._previous_sigint_handler)
  File "C:\pypy\lib-python\3\signal.py", line 47, in signal
    handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
ValueError: signal only works in main thread or with __pypy__.thread.enable_sign
als()

Comments (7)

  1. Armin Rigo

    It looks like a CPython bug. Running this fails in the same way on CPython:

    import _thread
    import pdb 
    import time
    
    pdb.set_trace()
    
    def f():
        pdb.set_trace()
    
    _thread.start_new_thread(f, ())
    
    time.sleep(100)
    

    Press "c" the first time. Tested with CPython 3.5 and 3.7.

  2. Log in to comment