Skip to content

Commit 25854c5

Browse files
committed
make web.profiler work on Windows (tx asmo) (Bug#325139)
1 parent 6ec4c5f commit 25854c5

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

web/utils.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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\ntook '+ 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

911919
profile = Profile

0 commit comments

Comments
 (0)