question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enable PyCharm debugger to automatically attach to worker processes by patching startup command using PyDev

See original GitHub issue

Describe your feature request

Currently, Local mode is the only feasible way to debug Ray worker/actor code, but it would be great if debugging worked in non-local mode out of the box when using PyCharm.

PyCharm patches (see e.g. description here) all Python functions that are used to start new processes when launched in Debug mode (using pydev_monkey.monkey_patch_module) - so whenever you launch new subprocesses in Python (including using e.g. multiprocessing), debugger attaches automatically - and everything works seamlessly.

The reason it doesn’t work with Ray is because worker processes/actors are started by Cython / native code, bypassing PyDev patches. If you were to patch the Python startup command within Cython code whenever PyDev is used (same as how PyCharm does it for respective Python functions) then debugging should just magically start working - and you wouldn’t even need Local mode anymore, if you use PyCharm.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:17
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

16reactions
austinnichols101commented, Jun 12, 2021

This seemingly small change would make a huge difference in my workflow.

The PyCharm debugger is outstanding, but unfortunately useless with Ray actor code. I can debug everything except for the actors which is a huge pain.

7reactions
nirvana-msucommented, Feb 9, 2021

@pcmoritz yeah I’ve seen that, but I don’t want to be “dropped into a PDB session”. What I want is an actual interactive debugging in PyCharm where I can step through the code line-by-line in my IDE and use all the debugging abilities that come with IDE. This is infinitely more useful and more user-friendly than pdb. And it generally works perfectly out of the box, including for sub-processes launched from Python - and should work with Ray workers as well if we were to patch python worker launch command accordingly (to invoke PyDev).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Attach to process | PyCharm Documentation - JetBrains
PyCharm provides a way to attach the debugger to to a Python local process, while running a Python script launched either from your ......
Read more >
Python Debugger | PyCharm Documentation - JetBrains
Use this page to configure Python debug options. ... PyCharm will automatically attach all subprocesses of the process being debugged.
Read more >
Pycharm debugger doesn't stop at any breakpoint
I setup a tox project in my pycharm, but it never stop at any breakpoints during debugging. The command it generates at the...
Read more >
Debug won't work in subprocess
Drop into debugger on failed tests Clicked. PyQt compatible Auto. For Attach To Process show processes with names containing: python.
Read more >
Run/Debug Configuration: Python Debug - PyCharm - JetBrains
Add pydevd-pycharm.egg from the PyCharm installation to the Python path or execute. Example: pip install pydevd-pycharm~=191.3490. See procedure description in ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found