Add support for PyCharm Pro's Remote Debug Server#5674
Add support for PyCharm Pro's Remote Debug Server#5674cognifloyd wants to merge 4 commits intomasterfrom
Conversation
|
just fyi. pycharm pro is operated by Russia.
…On Mon, Jul 18, 2022 at 4:21 PM Jacob Floyd ***@***.***> wrote:
Allow debugging st2 services in PyCharm Pro's Remote Debug Server.
To enable debugging, before starting the st2 process(es), you need to:
- install pydevd-pycharm (use the version specific to your pycharm
install) in StackStorm's virtualenv.
- set the ST2_PYCHARM_DEBUG environment var to something non-empty
like "true".
- (optional) set environment vars ST2_PYCHARM_DEBUG_HOST and
ST2_PYCHARM_DEBUG_PORT if pycharm is listening somewhere other than
localhost:5000.
see:
https://www.jetbrains.com/help/pycharm/remote-debugging-with-product.html#remote-debug-config
------------------------------
You can view, comment on, or merge this pull request online at:
#5674
Commit Summary
- 69572e9
<69572e9>
allow for debugging in pycharm
- e2bb9a6
<e2bb9a6>
add changelog entry
File Changes
(2 files <https://github.com/StackStorm/st2/pull/5674/files>)
- *M* CHANGELOG.rst
<https://github.com/StackStorm/st2/pull/5674/files#diff-2c623f3c6a917be56c59d43279244996836262cb1e12d9d0786c9c49eef6b43c>
(13)
- *M* st2common/st2common/util/monkey_patch.py
<https://github.com/StackStorm/st2/pull/5674/files#diff-a9d1208b198addd761599450ce7fdddc94c2433cdb3d3ab08a6507d3bd0b6add>
(22)
Patch Links:
- https://github.com/StackStorm/st2/pull/5674.patch
- https://github.com/StackStorm/st2/pull/5674.diff
—
Reply to this email directly, view it on GitHub
<#5674>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACZ5TINA4WEN7BAX3ERVIC3VUWACLANCNFSM5342TKPA>
.
You are receiving this because your review was requested.Message ID:
***@***.***>
|
|
@guzzijones JetBrains is based in the Czech Republic which became a state in 1993. It's predecessor, Czechoslovakia, escaped Soviet control in 1989. Also, JetBrains has suspended operations in Russia due to the invasion of Ukraine: https://blog.jetbrains.com/blog/2022/03/11/jetbrains-statement-on-ukraine/ |
cognifloyd
left a comment
There was a problem hiding this comment.
I can see how including something IDE-specific is distasteful, but I believe it is warranted as yet-another-cost of our reliance on eventlet.
It is impossible afaik to hook the debugger into eventlet-based code without changing the sources (adding a call before eventlet.monkey_patch()). For normal python processes, there are several other ways to attach a debugger to the process, but this is the best way I've found with st2 code so far.
I've isolated these codepaths so that it is as minimal as possible, but if there's another way to enable using a debugger, I'm open to that.
| # 3. Check for ST2_PYCHARM_DEBUG env var | ||
| if os.environ.get("ST2_PYCHARM_DEBUG", False): | ||
| return True |
There was a problem hiding this comment.
This part is not pycharm specific - it allows enabling debug mode via env var instead of changing the cli args.
| # 3. Check for ST2_PYCHARM_DEBUG env var | |
| if os.environ.get("ST2_PYCHARM_DEBUG", False): | |
| return True | |
| # 3. Check for ST2_DEBUG env var | |
| if os.environ.get("ST2_DEBUG", False): | |
| return True |
There was a problem hiding this comment.
OK I split this change into a separate PR: #5675
| if os.environ.get("ST2_PYCHARM_DEBUG", False): | ||
|
|
||
| # pydevd_pycharm uses this to save copies of stdlib modules before | ||
| # eventlet monkey patches them, or the debugger will not work. | ||
| # see: https://intellij-support.jetbrains.com/hc/en-us/community/posts/360000333980 | ||
| os.environ["GEVENT_SUPPORT"] = "True" | ||
|
|
||
| import pydevd_pycharm | ||
|
|
||
| pydevd_pycharm.settrace( |
There was a problem hiding this comment.
@armab Do you have a recommendation on how we can make this extensible so that people can inject whatever debugger before monkey_patching occurs?
There was a problem hiding this comment.
What about something like:
def monkey_patch(patch_thread=None):
"""
...
"""
use_debugger = is_use_debugger_flag_provided()
if use_debugger:
try:
from st2_3rd_party_debugger import pre_monkey_patch
except ImportError:
pass
else:
pre_monkey_patch()
...
import eventlet
...
if patch_thread is None:
patch_thread = not use_debugger
eventlet.monkey_patch(...)
...Then, I would only need to install a package in the st2 virtualenv that provides a pycharm-specific version of the st2_3rd_party_debugger module.
@armab what do you think of this solution for enabling me to inject the debugger without adding anything IDE-specific, and without patching the st2 code.
|
Dang. All this time we been told we cannot use pycharm due to its Russian
connection.
…On Mon, Jul 18, 2022 at 12:41 PM Jacob Floyd ***@***.***> wrote:
@guzzijones <https://github.com/guzzijones> JetBrains is based in the Czech
Republic <https://en.wikipedia.org/wiki/Czech_Republic> which became a
state in 1993. It's prdecessor. Czechoslovakia escaped Soviet control in
1989.
Also, JetBrains has suspended operations in Russia due to the invasion of
Ukraine:
https://blog.jetbrains.com/blog/2022/03/11/jetbrains-statement-on-ukraine/
—
Reply to this email directly, view it on GitHub
<#5674 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACZ5TIIZOYYC5LB2KHCLZWLVUWCLBANCNFSM5342TKPA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Allow debugging st2 services in PyCharm Pro's Remote Debug Server.
To enable debugging, before starting the st2 process(es), you need to:
ST2_PYCHARM_DEBUGenvironment var to something non-empty like "true".ST2_PYCHARM_DEBUG_HOSTandST2_PYCHARM_DEBUG_PORTif pycharm is listening somewhere other thanlocalhost:5000.see: https://www.jetbrains.com/help/pycharm/remote-debugging-with-product.html#remote-debug-config