473,395 Members | 1,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

using breakpoints in a normal interactive session

Is there a way to temporarily halt execution of a script (without using
a debugger) and have it put you in an interactive session where you
have access to the locals? And possibly resume? For example:
def a(): .... x = 1
.... magic_breakpoint()
.... y = 1
.... print "got here"
.... a() Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 3, in a
File "<stdin>", line 2, in magic_breakpoint x 1 y Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'y' is not defined magic_resume() got here x

Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'x' is not defined

Feb 22 '06 #1
4 1222
da******@gmail.com writes:
Is there a way to temporarily halt execution of a script (without using
a debugger) and have it put you in an interactive session where you
have access to the locals?
Here's what I was able to do using the Extended Python debugger.
http://bashdb.sourceforge.net/pydb/. I'm sure there's a similar (if
not even simpler) way to do this in the stock debugger; but I'll let
others suggest that ;-)

First add this routine:

def call_debugger():
from pydbdisp import Display, DisplayNode
import pydb, inspect, sys
try:
raise Exception
except:
frame=inspect.currentframe()
p = pydb.Pdb()
p.reset()
p.display = Display()
p._program_sys_argv = list(sys.argv)
p.interaction(frame, sys.exc_traceback)

And then call it from your program as you indicated below for
"magic_breakpoint()". For "magic_resume()" just issue "quit"
"continue" or give a termanal EOF.

That the above routine is so long suggests some initialization
probably should be moved around. And in a future release (if there is
one), I'll consider adding something like the above routine.
And possibly resume? For example:
def a(): ... x = 1
... magic_breakpoint()
... y = 1
... print "got here"
... a() Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 3, in a
File "<stdin>", line 2, in magic_breakpoint x 1 y Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'y' is not defined magic_resume() got here x

Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'x' is not defined

Feb 22 '06 #2
da******@gmail.com wrote:
Is there a way to temporarily halt execution of a script (without using
a debugger) and have it put you in an interactive session where you
have access to the locals? And possibly resume? For example:

def a():
... x = 1
... magic_breakpoint()
... y = 1
... print "got here"
...
a()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 3, in a
File "<stdin>", line 2, in magic_breakpoint
x
1
y
Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'y' is not defined
magic_resume()
got here
x


Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'x' is not defined


you can use the standard-library code module for that: instead of
magic_breakpoint() just call code.interact(local=locals()). The
magic_resume() would be a regular Ctrl-D (or Ctrl-Z Enter under
windows). You can also package this nicely into a convenient function,
see for example the third example on the following page:

http://effbot.org/librarybook/code.htm

Cheers,

Carl Friedrich Bolz

Feb 23 '06 #3
In revising pydb the code and documentation for the routine originally
described, I learn that the pdb equivalent (sort of) is called
set_trace().

However set_trace() will terminate the program when you quit the
debugger, so I've retained this routine and made a couple of
corrections -- in particular to support a restart and make "show args"
work. The changes are in pydb's CVS. Lacking a better name, the
routine is called "debugger".

There is one other difference between set_trace() and debugger(). In
set_trace you stop at the statement following set_trace(), With
debugger() the call trace shows you in debugger and you may need to
switch to the next most-recent call frame to get info about the
program being debugged.

A downside of the debugger() approach is that debug session
information can't be saved between calls: each call is a new instance
of the debugger and when it is left via "quit" the instance is
destroyed. (In the case of pydb.set_trace() the issue never comes up
because the program is terminated on exit.)

ro***@panix.com (R. Bernstein) writes:
Here's what I was able to do using the Extended Python debugger.
http://bashdb.sourceforge.net/pydb/. ....

Feb 23 '06 #4
Carl -- Perfect! That is exactly what I want. I hoped it would be
that easy. Thanks for taking the time to post the solution.

Feb 23 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: qwweeeit | last post by:
Hi all, is it possible to enter an interactive session and automatically do some initialization? I explain better: I want that when I start interactive Python on a console (I use Linux) two...
1
by: Bucky Pollard | last post by:
I have a web service that needs to create a batch file and call it (since there are no APIs for the functionality I am looking for). I am using the Process and ProcessStartInfo objects. When I try...
2
by: WJ | last post by:
I have three ASPX pages: 1. "WebForm1.aspx" is interactive, responsible for calling a web site (https://www.payMe.com) with $$$. It is working fine. 2. "WebForm2.aspx" is non-interactive, a...
5
by: Åženol Akbulak | last post by:
Hello; I use in my web application FormsAuthentication. Also I use Session state (InProc). When a user logged in, I can read Session parameters. (For example Session). Problem is that, when...
13
by: | last post by:
Simple question, I think... I'm storing an object in the Session object. In the code behind I read that object: trx = CType(Session("Transaction"), BOCSTransaction) If I change any...
1
by: jeem | last post by:
I am using ActiveState Komodo 3.5 to work on a large python 2.4 application with an extensive UI... I am attempting to debug the application and am setting breakpoints in 4 different *.py files.....
5
by: venner | last post by:
I'm having an issue with an ASP.NET website after upgrading to ASP.NET 2.0. The website makes use of a central authentication service (CAS) provided at the university I work for. Each page checks...
13
by: Marvin Zhang | last post by:
Hi, I'm not familiar with web programming, but I have a problem here. I have a page. When a user click one button on it, I will use AJAX to request a PHP script which will do a bunch of tasks,...
1
by: Shawn Milochik | last post by:
Here's a more "English" version of what people are trying to explain: When you log into a Unix session, certain files in your home directory are read and add environment variables to your...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.