@@ -885,9 +885,11 @@ class Profile:
885885 def __init__ (self , func ):
886886 self .func = func
887887 def __call__ (self , * args ): ##, **kw): kw unused
888- import hotshot , hotshot .stats , tempfile ##, time already imported
889- temp = tempfile .NamedTemporaryFile ()
890- prof = hotshot .Profile (temp .name )
888+ import hotshot , hotshot .stats , os , tempfile ##, time already imported
889+ f , filename = tempfile .mkstemp ()
890+ os .close (f )
891+
892+ prof = hotshot .Profile (filename )
891893
892894 stime = time .time ()
893895 result = prof .runcall (self .func , * args )
@@ -896,7 +898,7 @@ def __call__(self, *args): ##, **kw): kw unused
896898
897899 import cStringIO
898900 out = cStringIO .StringIO ()
899- stats = hotshot .stats .load (temp . name )
901+ stats = hotshot .stats .load (filename )
900902 stats .stream = out
901903 stats .strip_dirs ()
902904 stats .sort_stats ('time' , 'calls' )
@@ -906,6 +908,12 @@ def __call__(self, *args): ##, **kw): kw unused
906908 x = '\n \n took ' + str (stime ) + ' seconds\n '
907909 x += out .getvalue ()
908910
911+ # remove the tempfile
912+ try :
913+ os .remove (filename )
914+ except IOError :
915+ pass
916+
909917 return result , x
910918
911919profile = Profile
0 commit comments