Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem with profiler module

0 views
Skip to first unread message

Tomaz Ficko

unread,
May 12, 1999, 3:00:00 AM5/12/99
to
I have problem with profiler module. Below is listing of python
interpreter session. I can run profiler from command line with now
problem. What is the problem?

Python 1.5.2 (#1, Apr 30 1999, 22:36:07) [GCC 2.7.2] on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> def f(x):
x.append(1)


>>> import profile
>>> a=[]
>>> profile.run('f(a)')
Traceback (innermost last):
File "<pyshell#6>", line 1, in ?
profile.run("f(a)")
File "/usr/local/lib/python1.5/profile.py", line 62, in run
prof = prof.run(statement)
File "/usr/local/lib/python1.5/profile.py", line 348, in run
return self.runctx(cmd, dict, dict)
File "/usr/local/lib/python1.5/profile.py", line 354, in runctx
exec cmd in globals, locals
File "<string>", line 1, in ?
NameError: f

Randall Hopper

unread,
May 12, 1999, 3:00:00 AM5/12/99
to Tomaz Ficko, pytho...@python.org
Tomaz Ficko:

Having gone through this myself recently (albeit not in idle), you
might try:

import profile
a=[]
prof = profile.Profile()
prof.runctx( 'f(a)', globals(), locals() )
prof.print_stats()

If that works, you can just define:

import profile
def runctx(statement, globals, locals, *args):
prof = profile.Profile()
try:
prof = prof.runctx( statement, globals, locals )
except SystemExit:
pass
if args:
prof.dump_stats(args[0])
else:
return prof.print_stats()

and then subsequently use:

a=[]
runctx( 'f(a)', globals(), locals() )

Hopefully this convenience function will be added to profile.py in the next
version.

Randall

0 new messages