Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

debugging - Method to peek at a Python program running right now

Is it possible to find any information about what a Python program running right now is doing without interrupting it?

Also, if it isn't possible, is there anyway to crash a running Python program so that I can at least get a stacktrace (using PyDev on Ubuntu)?

I know I should have used logs or run it in debug mode or inserted a statement to run the debugger...

Related questions

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you place

import code
code.interact(local=locals())

at any point in your script, python will instantiate a python shell at exactly that point that has access to everything in the state of the script at that point. ^D exits the shell and resumes execution past that point.

You can even modify the state at that point from the shell, call functions, etc.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...