[Pkg-bazaar-commits] ./bzr/unstable r239: - remove profiler temporary file when done

mbp at sourcefrog.net mbp at sourcefrog.net
Fri Apr 10 07:51:31 UTC 2009


------------------------------------------------------------
revno: 239
committer: mbp at sourcefrog.net
timestamp: Mon 2005-04-11 12:53:57 +1000
message:
  - remove profiler temporary file when done
modified:
  NEWS
  bzrlib/commands.py
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS	2005-04-11 02:50:08 +0000
+++ b/NEWS	2005-04-11 02:53:57 +0000
@@ -18,7 +18,8 @@
 
     * More tests in test.sh.
 
-    * Write profile data to a temporary file not into working directory.
+    * Write profile data to a temporary file not into working
+      directory and delete it when done.
 
 
 bzr-0.0.3  2005-04-06

=== modified file 'bzrlib/commands.py'
--- a/bzrlib/commands.py	2005-04-11 02:50:08 +0000
+++ b/bzrlib/commands.py	2005-04-11 02:53:57 +0000
@@ -986,20 +986,25 @@
 
     if profile:
         import hotshot
-        pfname = tempfile.mkstemp()[1]
-        prof = hotshot.Profile(pfname)
-        ret = prof.runcall(cmd_handler, **cmdargs) or 0
-        prof.close()
-
-        import hotshot.stats
-        stats = hotshot.stats.load(pfname)
-        #stats.strip_dirs()
-        stats.sort_stats('time')
-        ## XXX: Might like to write to stderr or the trace file instead but
-        ## print_stats seems hardcoded to stdout
-        stats.print_stats(20)
-
-        return ret
+        pffileno, pfname = tempfile.mkstemp()
+        try:
+            prof = hotshot.Profile(pfname)
+            ret = prof.runcall(cmd_handler, **cmdargs) or 0
+            prof.close()
+
+            import hotshot.stats
+            stats = hotshot.stats.load(pfname)
+            #stats.strip_dirs()
+            stats.sort_stats('time')
+            ## XXX: Might like to write to stderr or the trace file instead but
+            ## print_stats seems hardcoded to stdout
+            stats.print_stats(20)
+            
+            return ret
+
+        finally:
+            os.close(pffileno)
+            os.remove(pfname)
     else:
         return cmd_handler(**cmdargs) or 0
 



More information about the Pkg-bazaar-commits mailing list