Hi Anand, I'm sorry I dont have any experience with sys.settrace(). I'm a big fan of pdb.set_trace() and it serves me well. I'll let someone else answer your specific question.
Jeff On Sat, Jan 30, 2010 at 11:53 AM, <[email protected]> wrote: > Hi Jeff, > > I am successful in debugging pdb.set_trace() > but sys.settrace(), not sure how to add, i am trying in various function > with argument as the function name > as per ref: > http://www.dalkescientific.com/writings/diary/archive/2005/04/20/tracing_python_code.html > > I work in multifile environment( say thousands ) and i am not sure where > exactly is the right place to call. > ex: I have a def config(value) i used this command sys.settrace(config) > but my eclipse cribs .. > > Any suggestions please. > > Regards > -- Anand > > > > -----Original Message----- > From: [email protected] > To: [email protected] > Cc: [email protected] > Sent: Sat, Jan 30, 2010 6:18 pm > Subject: Re: BangPypers Digest, Vol 29, Issue 31 > > Hi Jeff, > > Apologies for the delay, Unfortunately this email has gone to my spam > folder and could only see fortunately. > I am really thankful for the response. > > What is the website i could log in to see the responses please i have > forgotten over the period of time. > > python.org from there i am trying to go to bangalore but cannot go past > the subscription page ..http://mail.python.org/mailman/listinfo/bangpypers > > > Should i use the function > > import pdb; pdb.set_trace() in every function or should i create a def or > class and call the instance separately. Sorry i am naive. > > > > > Thanks in advance > > > > > Cheers > > > -- Anand > > > -----Original Message----- > From: [email protected] > To: [email protected] > Sent: Mon, Jan 25, 2010 12:00 am > Subject: BangPypers Digest, Vol 29, Issue 31 > > Send BangPypers mailing list submissions to > > > [email protected] > > > > > To subscribe or unsubscribe via the World Wide Web, visit > > > http://mail.python.org/mailman/listinfo/bangpypers > > > or, via email, send a message with subject or body 'help' to > > > [email protected] > > > > > You can reach the person managing the list at > > > [email protected] > > > > > When replying, please edit your Subject line so it is more specific > > > than "Re: Contents of BangPypers digest..." > > > > > > > Today's Topics: > > > > > 1. Re: January user group meeting (Arvind Jamuna Dixit) > > > 2. Re: January user group meeting (Noufal Ibrahim) > > > 3. Python Maintainence code: Debugging, Tracing and Profiling > > > help ([email protected]) > > > 4. Re: Python Maintainence code: Debugging, Tracing and > > > Profiling help (Jeffrey Jose) > > > > > > > ---------------------------------------------------------------------- > > > > > Message: 1 > > > Date: Sat, 23 Jan 2010 20:12:13 +0530 > > > From: Arvind Jamuna Dixit <[email protected]> > > > To: Bangalore Python Users Group - India <[email protected]> > > > Subject: Re: [BangPypers] January user group meeting > > > Message-ID: > > > <[email protected]> > > > Content-Type: text/plain; charset=ISO-8859-1 > > > > > How did the meet go. Couldn't come as I got stuck in MG Road traffic. > > > > > On Fri, Jan 22, 2010 at 5:19 PM, Noufal Ibrahim <[email protected]> wrote: > > > > > > Okay. This is set in stone. Hope to see you all there! > > > > > > > > On Wed, Jan 20, 2010 at 11:26 AM, Noufal Ibrahim <[email protected]> wrote: > > > > > So are we decided? > > > > > > > > > > Date : Jan 23 > > > > > Time : 1530 > > > > > Venue : ThoughtWorks, Diamond District > > > > > Topics : Baiju - Buildbot > > > > > Noufal - py.test. > > > > > > > > > > Fine? Vishal had a -1 for 23. If there many others, we can change the > > > > date > > > > > to 24th. > > > > > > > > > > > > > > > > > > > > -- > > > > > ~noufal > > > > > http://nibrahim.net.in > > > > > > > > > > > > > > > > > > > > > -- > > > > ~noufal > > > > http://nibrahim.net.in > > > > _______________________________________________ > > > > BangPypers mailing list > > > > [email protected] > > > > http://mail.python.org/mailman/listinfo/bangpypers > > > > > > > > > > > > > -- > > > Arvind > > > > > > > ------------------------------ > > > > > Message: 2 > > > Date: Sat, 23 Jan 2010 21:48:28 +0530 > > > From: Noufal Ibrahim <[email protected]> > > > To: Bangalore Python Users Group - India <[email protected]> > > > Subject: Re: [BangPypers] January user group meeting > > > Message-ID: > > > <[email protected]> > > > Content-Type: text/plain; charset=ISO-8859-1 > > > > > On Sat, Jan 23, 2010 at 8:12 PM, Arvind Jamuna Dixit <[email protected]> wrote: > > > > How did the meet go. Couldn't come as I got stuck in MG Road traffic.[..] > > > > > Pretty well. Baiju's presentation on using using buildout to easily > > > configure buildbot was nice. I also learnt that if you 'activate' a > > > virtualenv, you get a 'deactivate' command to go back to your system > > > wide install. Neat. :) > > > > > -- > > > ~noufal > > http://nibrahim.net.in > > > > > > > ------------------------------ > > > > > Message: 3 > > > Date: Sat, 23 Jan 2010 18:04:20 -0500 > > > From: [email protected] > > > To: [email protected] > > > Subject: [BangPypers] Python Maintainence code: Debugging, Tracing and > > > Profiling help > > > Message-ID: <[email protected]> > > > Content-Type: text/plain; charset="us-ascii" > > > > > > > > > > > > Hi Experts, > > > > > I am back to python after a while of just formal introduction. Thistime i have > > > to manage a huge files with numerous functions, i amdebugging a issue right > now > > > and would require to understand the flow ofthe code. > > > > > Please can you help me on what can i do to have better understanding ofthe > > > profiling of classes, defs invoked each time and how to read them. > > > > > The ones i plan to do is to insert lot of prints in every class, defs ex: > print > > > self.__class__.__name__ in every def, to see the flow which is tedious and > time > > > consuming as the size of files and project is huge. > > > > > Any suggestions please and advice please. > > > > > PS: how to post to comp.lang.python newsgroup please?? > > > > > > > > Cheers > > > Anand > > > > > > > > > > > > > > > > > > > ------------------------------ > > > > > Message: 4 > > > Date: Sun, 24 Jan 2010 13:35:13 +0530 > > > From: Jeffrey Jose <[email protected]> > > > To: Bangalore Python Users Group - India <[email protected]> > > > Subject: Re: [BangPypers] Python Maintainence code: Debugging, Tracing > > > and Profiling help > > > Message-ID: > > > <[email protected]> > > > Content-Type: text/plain; charset=ISO-8859-1 > > > > > Hi Anand, > > > > > I can talk a lil bit about your 2 queries. Debugging and seeing the flow of > > > the program. > > > > > *A. Debugging* > > > > > Surprisingly both of them come under the same banner. One of the reasons you > > > debug is to see how the code progresses. For debugging I highly recommend > > > Python Debugger. It would look a lot odd the first time you invoke it, but > > > trust me with a few neat tricks you'd be using it all the time. > > > > > There's just one thing you need to do to summon the Python Debugger. Insert > > > this one line in your code. > > > > > import pdb; pdb.set_trace() > > > > > The next time you run the code, it would drop into the debugger (you just > > > set a trace point). When you have the debugger prompt, you have access to > > > all the variables, stacktrace etc. You need to know a few commands to get > > > around. > > > > > c -> Continue (till the end of the program or till the next breakpoint) > > > n -> Execute next step > > > l -> See where you are > > > s -> Step into a function. > > > > > I accept this is not a natural way of doing things.. That's where we come to > > > the 'with-a-few-tricks-you'd-be-doing-this-all-the-time' > > > And the trick is this. Invoke Ipython from pdb. The good thing is you get > > > tab-competition (which pdb lacks). You can try out all kinds of things. > > > Introspect, import other modules, try and see the next line and see what its > > > output 'would be'. Its sweet. I highly recommend you take a look at this. > > > > > Starting ipython from > > > pdb<http://libreamoi.com/index.php/starting-ipython-from-pdb/>- > <http://libreamoi.com/index.php/starting-ipython-from-pdb/%3E-> > > http://libreamoi.com/index.php/starting-ipython-from-pdb/ > > > Hit Ctrl-D to exit from Ipython to go to pdb again and hit 'c' to continue > > > the program. While you're at pdb, you can still go into ipython again. > > > > > Remember Ipython is a regular prompt, so you cant do debugger-y things like > > > Step Into, Continue etc. For that you'll have to come 'out' of Ipython to > > > pdb. You can go back to Ipython anytime. > > > > > *B. Seeing Your Program Flow* > > > > > If I understand you correctly, I've seen this problem hit me lot of times. > > > If you're working on others code, and all of a sudden you wanna > > > understand/fix them - you'd be sitting there thinking - Damn, *how* does > > > this code work. I can see a lot of functions and I get what it does. But > > > when does this one get called. I see this main call from main() .. but is > > > there another place where it gets called ?. If so what are the arguments. > > > What does it return on this one specific call etc. > > > > > While its technically possible to do next-next-next using Python Debugger to > > > step through the program and sometimes that's all can you do. > > > But there's a much better way than inserting > > > > > print "Called me!" > > > print "Done with me!" > > > > > etc. > > > > > The idea here is to use sys.settrace() to insert to a utility function which > > > gets called before any important events. Events include, > > > # execution of any line (that means all the time) > > > # calling a function > > > # return from a function > > > # encountering an exception > > > > > This means your utility function can go .. hmm .. is this a function call ? > > > .. if so gimme the name of the caller and name of the function and let me > > > print it. > > > > > When you run the code you'd get a huge output with prints which shows the > > > flow of the program. > > > Again, refer this page for a better understanding. > > > Tracing Your Program As It Runs - > > http://blog.doughellmann.com/2009/11/pymotw-sys-part-5-tracing-your-program.html > > > One caution : Do Not Abuse sys.settrace() Use sys.settrace() for debugging > > > only. You might be tempted to do crazy things like .. during every function > > > call .. I'll authorize the user or something. That better be done using > > > different methods. Just saying :) > > > > > > > Unfortunately, the place where I work doesnt care much about performance (or > > > unnecessary optimization) for the python code. So I cant help you there. > > > I'll let others chip in for those stuff. > > > > > HTH > > > Jeff > > > > > > > On Sun, Jan 24, 2010 at 4:34 AM, <[email protected]> wrote: > > > > > > > > > > > > > > > > > > Hi Experts, > > > > > > > > I am back to python after a while of just formal introduction. Thistime i > > > > have to manage a huge files with numerous functions, i am debugging a issue > > > > right now and would require to understand the flow ofthe code. > > > > > > > > Please can you help me on what can i do to have better understanding ofthe > > > > profiling of classes, defs invoked each time and how to read them. > > > > > > > > The ones i plan to do is to insert lot of prints in every class, defs ex: > > > > print self.__class__.__name__ in every def, to see the flow which is tedious > > > > and time consuming as the size of files and project is huge. > > > > > > > > Any suggestions please and advice please. > > > > > > > > PS: how to post to comp.lang.python newsgroup please?? > > > > > > > > > > > > Cheers > > > > Anand > > > > > > > > > > > > > > > > > > > > > > > > _______________________________________________ > > > > BangPypers mailing list > > > > [email protected] > > > > http://mail.python.org/mailman/listinfo/bangpypers > > > > > > > > > > > ------------------------------ > > > > > _______________________________________________ > > > BangPypers mailing list > > [email protected] > > http://mail.python.org/mailman/listinfo/bangpypers > > > > > > > End of BangPypers Digest, Vol 29, Issue 31 > > > ****************************************** > > _______________________________________________ BangPypers mailing list [email protected] http://mail.python.org/mailman/listinfo/bangpypers
