Can't figure out how to debug with breakpoints

263 views
Skip to first unread message

jandyman...@gmail.com

unread,
Dec 30, 2015, 10:14:28 PM12/30/15
to Interactive Editor for Python
Hello,

Forgive my beginner mistakes, but I cannot seem to figure out how to get breakpoints to work. I can set them in the left margin and see a red filled circle next to the line I want to break at. However, when I call the function which has the breakpoint in it, the breakpoint is not hit, the function runs as if there is no breakpoint.

Background: I am a 40 year veteran programmer in scores of languages, but am a complete beginner in Python. I'm learning it so I can use SciPy as a Matlab alternative. So any setup that may be need to enable debugging is not something I will know anything about.

Thanks in advance for any help!

- Andy

Almar Klein

unread,
Dec 31, 2015, 3:41:36 PM12/31/15
to jandyman...@gmail.com, Interactive Editor for Python

Hi Andy,

 

One pitfall is that debugging does not work (i.e. execution does not stop at a breakpoint) for breakpoints in code that was executed as a cell. Could this be the problem?

 

Regards,

  Almar

--
You received this message because you are subscribed to the Google Groups "Interactive Editor for Python" group.
To unsubscribe from this group and stop receiving emails from it, send an email to iep_+uns...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

 

Almar Klein

unread,
Jan 4, 2016, 4:27:02 AM1/4/16
to Andrew Voelkel, Interactive Editor for Python

I don't think the problem is related to being executed as a cell, although I don't know precisely what that means. I assume it means that the code which contains the function with the breakpoint in it was "compiled" by using an "execute cell" command. ...

That's correct.


Since I posted the inquiry, I've experimented with pdb. After initially having similar problems with it, I did notice that the reason I could not set a breakpoint properly was because the file being debugged was in a folder which was not on Python's search path. Things started working when I modified the path to include the folder containing my source file. Could there be a similar issue with IEP debugging?

I would be surprised if it did, but then again, I don't see at the moment what the problem could be.

 
A more general but related question: Should I just be able to "execute selection" on a selection which contains a function definition with breakpoint in it, and then invoke that function from the interpreter window, and hit the breakpoint? I've tried both that, and "execute file" on with the current file containing the function definition with the breakpoint. In this case "current file" means the active tab of the editor pane of the IDE. Nothing seems to work.  

Ah sorry, both "exectute selection" and "execute cell" would *not* work. Any of the other run methods should work though, its a matter of the first line number of the code block being executed matching up with the file's line nr. It should probably be possible to fix that, but I haven't got to it.
 

Pdb breakpoint debugging did seem to work once I got the file on the search path, but doesn't seem integrated with the IEP based debugging. Are pdb and IEP debugging completely different animals?

They are different animals, bot work in a similar way and are both based on bdb, which is the sort of lower level debugging facility in Python.


I'm not sure what else to try. Maybe its possible for you to come up with a reproducable minimal example (consisting of one or two .py files). If I can reproduce the error locally, I'd have much more to work with.

- Almar

jandyman...@gmail.com

unread,
Jan 4, 2016, 5:50:55 PM1/4/16
to Interactive Editor for Python, jandyman...@gmail.com
Hi,

For some reason I did not get your reply earlier. So I was just about to try your suggestion and not use either "execute selection" or "execute cell", but now I cannot start IEP at all. I'm on OS X El Capitan, and I get "The application 'IEP' cannot be opened". Have you seen this before? I was going to try to install Anaconda to see if it solves another problem I was seeing, but I really don't think I've actually started the installation. Just thought I'd mention that.

The other problem I was having is that I can't seem to get IPython command history stuff to work like I think it should from reading the docs. I can get a history list with numbers using %hist -g <searchString>. But if I then say %recall 45 for command number 45, nothing appears on the command line. And I can't seem to find a single example of using the %recall command this way in Google.

Thanks for all help! I'm a bit frustrated at the moment. I think if I can get past this basic stuff it should go well, since it looks like the signal processing functions I'm used to having in Matlab are all present in some form in SciPy.

- Andy

jandyman...@gmail.com

unread,
Jan 4, 2016, 6:35:49 PM1/4/16
to Interactive Editor for Python, jandyman...@gmail.com
Hi,

I fixed the problem with IEP not running by deleting the whole folder heirarchy and recopying from the dmg file. 

I then got debugging working using "execute file". Hooray!

Questions:

I've noticed that what happens when you run code by "executing" from the menu is very different from what happens when you "import" that file from the shell. All sorts of namespace things are different, and in ways that I don't understand because I'm new to Python. I think the differences are a very good thing in that I suspect they protect you from name collisions by not polluting the global namespace by executing import statements within your source file in a global scope, in the case where the file with the import statements is itself being imported. Am I right about this? I know the sentence isn't that clear but I hope you get the gist of the question.

And more importantly, are there debug implications of these two different ways of executing code? On a related note - if I make changes to code, and then save and run "execute file" again, then debugging still seems coherent. Do I need to do both of these things after a code edit so that the debugger doesn't get confused.

Also, if you have any input on why I can't seem to get the %recall magic command to work with a line number, I'd love some help. I tried Spyder, and it behaves the same way.

But it did make me curious. Suppose I want update a component in Pyzo, either the IPython version or the SciPy version. Is this easy or hard?

Thanks again!

- Andy

On Wednesday, December 30, 2015 at 8:14:28 PM UTC-7, jandyman...@gmail.com wrote:

Almar Klein

unread,
Jan 7, 2016, 5:50:55 AM1/7/16
to jandyman...@gmail.com, Interactive Editor for Python

> I fixed the problem with IEP not running by deleting the whole folder heirarchy and recopying from the dmg file. 

> 

> I then got debugging working using "execute file". Hooray!

 

Yah!

 

 

> I've noticed that what happens when you run code by "executing" from the menu is very different from what happens when you "import" that file from the shell. All sorts of namespace things are different, and in ways that I don't understand because I'm new to Python. I think the differences are a very good thing in that I suspect they protect you from name collisions by not polluting the global namespace by executing import statements within your source file in a global scope, in the case where the file with the import statements is itself being imported. Am I right about this? I know the sentence isn't that clear but I hope you get the gist of the question.

 

Yes, this a python thing. Python makes much use of namespaces, which is a good thing. Basically, every module has its own namespace. And you can get access to a module by importing it (i.e. bringing it in the current namespace). There is also a “main” namespace corresponding to the namespace of the script being run.

 

I’m not sure what you’re trying to do, but its generally good practice to separate scripts from modules. Modules are files that you import elsewhere and provide certain functionality, but should generally not *do* much other than defining functions and classes. In scripts you can do whatever you like, naturally :)

 

You can make modules that you can also execute as a script. You can use `` if __name__ == ‘__main__’:`` to detect that its run as a script and then e.g. invoke any of the functions that it defines.

 

I hope this helps a bit.

 

 

> And more importantly, are there debug implications of these two different ways of executing code? On a related note - if I make changes to code, and then save and run "execute file" again, then debugging still seems coherent. Do I need to do both of these things after a code edit so that the debugger doesn't get confused.

 

There should not really be debug implications, except that code in a module is always associated with a module, whereas code being executed is not necessarily, but that’s why you should not execute selected or cell in code where there are breakpoints :)

 

If you re-execute a script in a running shell, everything gets updated fine. But modules, once imported, won’t re-import. You can force them to, but that can lead to nasty side effects. This is basically why IEP has “run as script”, which restarts the shell to ensure a clean sheet.

 

 

> Also, if you have any input on why I can't seem to get the %recall magic command to work with a line number, I'd love some help. I tried Spyder, and it behaves the same way.

 

That’s because the IPython shell in IEP is a bit of an odd mix of IEP and IPython. You’ve already encountered that it uses IEP’s debugging mechanism. Further, IEP takes care of the autocompletion (using a dropdown), and command history. Both of these functionalities in IPython are sort of ignored. I suspect that Spider has a similar cause.

 

 

> But it did make me curious. Suppose I want update a component in Pyzo, either the IPython version or the SciPy version. Is this easy or hard?

 

Easy. In the shell you can just do `conda update scipy` to get the latest. Pyzo is really just a pre-packaged conda distribution.

 

- Almar

 

 

> Thanks again!

> 

> - Andy


On Wednesday, December 30, 2015 at 8:14:28 PM UTC-7, jandyman...@gmail.com wrote:

Hello,

 

Forgive my beginner mistakes, but I cannot seem to figure out how to get breakpoints to work. I can set them in the left margin and see a red filled circle next to the line I want to break at. However, when I call the function which has the breakpoint in it, the breakpoint is not hit, the function runs as if there is no breakpoint.

 

Background: I am a 40 year veteran programmer in scores of languages, but am a complete beginner in Python. I'm learning it so I can use SciPy as a Matlab alternative. So any setup that may be need to enable debugging is not something I will know anything about.

 

Thanks in advance for any help!

 

- Andy

--

Reply all
Reply to author
Forward
0 new messages