How to disconnect from all debug sessions?

后端 未结 2 518
日久生厌
日久生厌 2021-02-13 18:41

During development I often end up with multiple live sessions. PyCharm gives me an option to close all debugger tabs (or all other tabs), but for each live session it brings up

相关标签:
2条回答
  • 2021-02-13 19:03

    Maybe the best answer to the question is to not start all these sessions in the first place. If what you really want to do is kill the existing session when you start the debugger, set the "Single instance only" option in the Run/Debug Configurations dialog.

    enter image description here

    Then each time you click the debug icon (or Shift+F9) it will stop the current session and start a new one. Before I figured out what this did, I would end up with a number of sessions still running even though I was no longer interested in them.

    The PyCharm help says the following, but in my experience, with this checked, restarting the debugger just kills off the current instance and starts a new one. This is useful when you don't want a bunch of old instances running, but it is critical when building a Django app and you don't want multiple instances trying to run at the same time.

    If this check box is selected, this run/debug configuration cannot be launched more
    than once.
    
    Every time a new run/debug configuration is launched, PyCharm checks the presence of 
    the other instances of the same run/debug configuration, and displays a confirmation
    dialog box. If you click OK in the confirmation dialog box, the first instance of
    the runner will be stopped, and the next one will take its place.
    
    This make sense, when usage of certain resources can cause conflicts, or when
    launching two run/debug configurations of the same type consumes too much of the CPU
    and memory resources. If this check box is not selected, it is possible to launch as
    many instances of the runner as required. So doing, each runner will start in its own
    tab of the Run tool window.
    
    0 讨论(0)
  • 2021-02-13 19:20

    I ran into this issue when using PyCharm for the first time. I assumed incorrectly that each time I ran the debugger, I was killing any existing run and starting a new one. I found no apparent way in the GUI to kill all of the python processes with open debugger connections, so I just did it in the terminal as follows:

    1. Find the processes you're debugging. In my case, I had over 100 processes before I realized what was going on. Just eyeball it to ensure correctness.

      ps ux | grep my_script_name | grep -v grep
      
    2. Send your list of PIDs to kill (assuming PID is column 2 in your ps output):

      kill -9 `ps ux | grep my_script_name | grep -v grep | awk '{print $2}'`
      
    3. Try closing the tabs in PyCharm. Debugger connections are closed, so it won't complain.

    0 讨论(0)
提交回复
热议问题