-
Notifications
You must be signed in to change notification settings - Fork 230
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
Easier way to set_trace #109
Comments
There's already Also, what about repeated imports? Will this trigger properly if you import the same thing twice? |
I didn't know about
|
I don't think repeated imports work. I'll buy it if you check. :) |
I'll play around with it tomorrow. |
Ah, I see what you mean now. Second imports won't trigger. We may have to register an import hook for this to work. And speaking of import hooks, in Python 3, all the import machinery is implemented in Python, meaning a single |
Import hooks may not help. The sys.modules cache is used before hooks are used, if I understand the documentation correctly. I played around with them and couldn't get them to work. I also tried monkeypatching sys.modules, but that didn't work either. I think I am able to get something that works by monkey-patching |
This lets you just run import pudb.b to trigger a set_trace(). It works by monkey-patching __builtins__.__import__. It does not yet work in Python 3.3, due to the new import mechanism. See inducer#109.
OK, the version in #110 works in Python 2, and probably Python < = 3.2. I think I just need to fiddle with the
|
By the way, I just noticed that all this importlib stuff from Python 3 is there in the stack even in normal |
Sorry, not sure I'm following. Can you explain what you mean? Thx! |
I agree, that's weird. Just to clarify, that's upon hitting the |
Yes, it's the The problem is that the set_trace() is called in the middle of an import, so you get all the import machinery in the stack. This only happens in Python 3.3 because the import machinery was rewritten in Python (as a frozen module) in that version (in previous versions, it was written in C and didn't take up any stack frames, or at least none visible to a tracing debugger). There is actually a second bug here, which is that the UI doesn't render correctly if you move up to the frame from the frozen module. I'm assuming this happens with any frozen module. PuDB should just remove frozen modules from the stack trace, or at least prevent from selecting them, as they aren't very useful (I guess removing them could be a bad idea because there is useful information there). Feel free to split this into a separate issue or issues. |
Well, it definitely shouldn't destroy the UI. I'd argue these modules should stay in the stack trace, but we probably shouldn't attempt to render their source. |
We should make it so
import pudb.b
does the same thing asimport pudb;pudb.set_trace()
. The latter is too much to type. Are you OK with the nameb
? If so, I'll implement this.The text was updated successfully, but these errors were encountered: