Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breakpoint right after pydevd.settrace call #17

Closed
Bonjour123 opened this issue Jun 3, 2022 · 6 comments
Closed

Breakpoint right after pydevd.settrace call #17

Bonjour123 opened this issue Jun 3, 2022 · 6 comments

Comments

@Bonjour123
Copy link

Bonjour123 commented Jun 3, 2022

When I detach the debugger (with the stop button inside pycharm) and then attach it again (with the run/rerun button), Pycharm always brings up the following file PyCharm2022.1\plugins\fusion_idea\lib\pydevd-1.9.0\pydevd_attach_to_process\attach_script.py
and breaks at the line

pydevd.settrace( port=port, host=host, stdoutToServer=True, stderrToServer=True, overwrite_prev_trace=True, suspend=False, trace_only_current_thread=False, patch_multiprocessing=False, )

I though that the problem was related to the line right before it:
if py_db is not None: py_db.dispose_and_kill_all_pydevd_threads(wait=False)

but I checked that dispose_and_kill_all_pydevd_threads is well defined, and changed wait to True.
But Pycharm still breaks right after the pydevd.settrace call

Also, it seems this issue is not a duplicate or related to this one

@JesusFreke
Copy link
Owner

Hmm. I don't think I've run into that. But I think I do have some pending fixes that I never got around to pushing. I'll check that today and get those pushed and released, and then let's see if it works for you with the new version.

@Bonjour123
Copy link
Author

Ok thank you !
I'll let you know if it get fixed

@JesusFreke
Copy link
Owner

I just looked at the pending changes I made, and it won't have any effect on the behavior you're seeing.

I just tried that myself and can reproduce the issue. I've actually ran into that before and tried to figure out what was causing it, but haven't had any success. I think it's probably something deep in the bowels of the integration of pydevd and IDEA/PyCharm.

You should still be able to debug though. Just resume execution from that initial breakpoint, and it should continue as normal.

@Bonjour123
Copy link
Author

So I've just ignored this bug untill now, when it really bothered me. I might have actually found the trick.
Copy C:\Users\[USER]\AppData\Roaming\JetBrains\PyCharm2022.1\plugins\fusion_idea\lib\pydevd-1.9.0\pydevd_attach_to_process\attach_script.py to the location of fusion_idea_addin
This allows us to make a relative import of it inside fusion_idea_addin.py by replacing import attach_script by from . import attach_script

Relative imports are important because otherwise the imported modules won't be reloaded inside Fusion360 python interpreter, and you would have to restart Fusion360 to see the changes in the imported modules.

Then, still in fusion_idea_addin.py, inside the attach function, replace the call to pydevd.settrace by:

    pydevd.settrace(
            port=port,
            host=host,
            stdoutToServer=True,
            stderrToServer=True,
            overwrite_prev_trace=True,
            suspend=True,
            trace_only_current_thread=False,
            patch_multiprocessing=False,
            stop_at_frame = False
        )

Notice the suspend=True, and stop_at_frame = False

While this is the only way I found to make it NOT stop inside attach_script.py, this is completely incoherent with the settrace sources:
suspend=True is supposed to actually simulate a breakpoint on settrace call, whereas the contrary happens

and stop_at_frame's default is supposed to be False, whereas explicitly setting it as False changes the function's behavior).

@JesusFreke
Copy link
Owner

Hmm. Do relative imports cause the module to be reloaded? I don't think that's the case? But I could be wrong. I do jump through some hoops elsewhere to ensure, e.g. the script module is reloaded.

But in any case, I'll give it a shot, and merge it in if it looks like it fixes the issue.

Thanks for investigating!

JesusFreke added a commit that referenced this issue Mar 19, 2023
This fixes issue #17, where the debugger would suspend within the
attach_script.py script, on subsequent attempts to attach to fusion,
after the first attach and detach.

Thanks for @Bonjour123 for digging into this and suggesting the fix!
@JesusFreke
Copy link
Owner

This should be fixed by 836187a. Thanks for digging into it and suggesting the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants