import types fails

Richie Hindle richie at entrian.com
Fri Aug 23 05:50:04 EDT 2002


Greg,

[Tim Peters]
> First run python with -vv and stare at the output.  With the -vv switch,
> Python displays a detailed account of (among other things) how imports get
> satisfied.

If that doesn't help, you could use the "Black box recorder" module
I posted recently to get a trace of each line of Python code
executed.  The last line of the log will be the line that caused the
hang (possibly a call into a C module).

In case you didn't see the thread ("How to do a program dump -
reposted"), here it is again:

>>> import blackbox, calendar
>>> blackbox.recordTo( open( 'log.txt', 'wt' ) )
>>> calendar.weekday( 2002, 8, 19 )
0
>>> ^Z

> type log.txt
<stdin>:0
<stdin>:1
d:\python\lib\calendar.py:46
d:\python\lib\calendar.py:47
d:\python\lib\calendar.py:48
d:\python\lib\calendar.py:49

To use it in a program, call `recordTo` conditionally on a
command-line switch or something.  With a bit of extra work,
you could get it to indent the log file to reflect the call
stack.

---------------------------- blackbox.py --------------------------

import sys

outputStream = None

def recordTo( stream ):
   global outputStream
   outputStream = stream
   sys.settrace( globalTrace )

def globalTrace( frame, event, arg ):
   if event == 'line':
      outputStream.write( "%s:%d\n" % \
         ( frame.f_code.co_filename, frame.f_lineno ) )
      outputStream.flush()
   elif event == 'exception':
      (exception, value, traceback) = arg
      outputStream.write( "%s:%d Exception: %s\n" % \
         ( frame.f_code.co_filename, frame.f_lineno, exception ) )
      outputStream.flush()
   
   return globalTrace

-------------------------------- end ------------------------------

-- 
Richie



More information about the Python-list mailing list