PyDev.Debugger icon indicating copy to clipboard operation
PyDev.Debugger copied to clipboard

pydevd error

Open lhughes41 opened this issue 4 years ago • 5 comments

Context: eclipse 4.13 and 4.16 on Windows 10 with pydev 7.6.0 (was not experiencing on prior pydev. Python 3.7.

"self.writer" shows up as value "None"

The error happened around this code in pydevd: with self.suspended_frames_manager.track_frames(self) as frames_tracker: frames_tracker.track(thread_id, frames_list) cmd = frames_tracker.create_thread_suspend_command(thread_id, stop_reason, message, suspend_type) self.writer.add_command(cmd)

Stack trace: File "_pydevd_bundle\pydevd_cython_win32_37_64.pyx", line 943, in _pydevd_bundle.pydevd_cython_win32_37_64.PyDBFrame.trace_dispatch File "_pydevd_bundle\pydevd_cython_win32_37_64.pyx", line 934, in _pydevd_bundle.pydevd_cython_win32_37_64.PyDBFrame.trace_dispatch File "_pydevd_bundle\pydevd_cython_win32_37_64.pyx", line 263, in _pydevd_bundle.pydevd_cython_win32_37_64.PyDBFrame.do_wait_suspend File "C:\Users\Chestnut41.eclipse\org.eclipse.platform_4.16.0_688013353_win32_win32_x86_64\plugins\org.python.pydev.core_7.6.0.202006041357\pysrc\pydevd.py", line 1822, in do_wait_suspend self.writer.add_command(cmd)

I am trying to get a narrowed "how to reproduce" for you (believe tied to breakpoint() call) but wanted to get this up right away.

lhughes41 avatar Jul 21 '20 13:07 lhughes41

Reproducing: This is probably already bad practice (so teach me ;-) ) but before 7.6.0 I was able to have breakpoint() calls in wrapped in except/try to get me pass them in non debug mode when triggered by some test. So I could be lazy about dealing with them short term while dealing with some more pressing issue but know they were there for me to stop execution once I entered debug mode ;-) In non debug mode execution would continue pass the below due to try/except:

    try:
        breakpoint()
        pass  # needed for F6 (stepover) to behave as expected (seems to just continue otherwise)
    except:
        pass

To repeat, above thus allowed me, when not quite so lazy, to could come back in debug mode and deal with the detected issue without having a fatal crash earlier stopping me from whatever my more immediate driving issue might be.

Now I get a cycling spew of the error show in prior message due to self.writer == None. I did trying putting in a trap for it in the upset lines in pydevd itself but this just led to a hanging busy cursor.

So I can work around by immediately fixing my own test that was calling it breakpoint but above structure was very convenient. LIke I said, I am sure there is a better way. But pre 7.6.0 this sufficed. Any short term workaround would be appreciated. Short term might by a tweka to pydevd or perhaps a better construct around the breakpoint() call to pass it successfully after it fires?

lhughes41 avatar Jul 21 '20 14:07 lhughes41

I was able to reproduce this calling that code more than 1 time.

Calling it the first time fails with:

Could not connect to 127.0.0.1: 5678
Traceback (most recent call last):
  File "C:\bin\LiClipse_620\plugins\org.python.pydev.core_7.6.0.202006041127\pysrc\_pydevd_bundle\pydevd_comm.py", line 534, in start_client
    s.connect((host, port))
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

which is correct, but other calls start giving errors such as:

  File "X:\Pydev\plugins\org.python.pydev.core\pysrc\pydevd.py", line 1827, in do_wait_suspend
    self.writer.add_command(cmd)
  AttributeError: 'NoneType' object has no attribute 'add_command'

fabioz avatar Jul 23 '20 12:07 fabioz

Yes that's it!

lhughes41 avatar Jul 23 '20 14:07 lhughes41

Note that I have to fix this is the debugger itself.

As a workaround you could do something as:

try:
    breakpoint()
except:
    import sys

    def skip_breakpointhook():
        print("Breakpoint not activated (debugger inactive)")

    sys.__breakpointhook__ = skip_breakpointhook
    import builtins

    builtins.breakpoint = skip_breakpointhook

So, subsequent calls to breakpoint() would do that print instead of breaking.

fabioz avatar Jul 23 '20 14:07 fabioz

Thank you. That worked!

And having a simple print like that after first connect failure would be nice long term IMHO. Since those connect fails tend to hang for a second or two.

lhughes41 avatar Jul 23 '20 15:07 lhughes41