I am using python 2.5 on windows. All I am doing is unpickling a large file开发者_JAVA技巧 (18MB - a list of dictionaries) and modifiying some of its values. Now this works fine. But when I add a couple of prints, IDLE restarts. And weirdly enough it seems to be happening where I added the print. I figured this out commenting and uncommenting things line by line. I added a try catch around the print, but am not able to catch anything. When does IDLE restart? And how do I catch any exceptions or errors it throws(if it does)?
Have you tried running your script from the command line rather than IDLE? Open a command prompt and type python
to enter the Python interpreter. See if it crashes there too.
Secondly, you should try using the pdb module for debugging your Python scripts. This is far more effective than print statements since you can step through your code and check values at any point during the debug session.
import pdb
test_var = 'this is a test'
# set this whenever you want to start a breakpoint
pdb.set_trace()
In a pdb debug session you can step through lines by pressing 'n' and print values directly using the print statement. For example, you could:
> print test_var
'this is a test'
Enable the debugger and see if it tells you anything.
精彩评论