web.profiler does not work on Windows

Bug #325139 reported by asmo on 2009-02-04
Affects Status Importance Assigned to Milestone
Anand Chitipothu

Bug Description

As discussed here, web.profiler fails to create temporary file on Windows.


Ben Corneu suggested this fix:

looks like it's a bug in utils.py. It uses
tempfile.NamedTemporaryFile() to generate a temp file. On Windows the
file cannot be opened a second time. Using tempfile.mkstemp() instead
works but you lose the guaranteed cleanup of the temp file.


...Whether the name can be used to open the file a second time, while
the named temporary file is still open, varies across platforms (it can
be so used on Unix; it cannot on Windows NT or later)....

here's my fix for it.

Line 733 of utils.py
    def __call__(self, *args): ##, **kw): kw unused
        import hotshot, hotshot.stats, tempfile, os ##, time already
        temp = tempfile.mkstemp()
        temp_filename = temp[1]
        prof = hotshot.Profile(temp_filename)
        stime = time.time()
        result = prof.runcall(self.func, *args)
        stime = time.time() - stime
        import cStringIO
        out = cStringIO.StringIO()
        stats = hotshot.stats.load(temp_filename)
        #delete the temp file as son as we are done with it
        stats.stream = out
        stats.sort_stats('time', 'calls')
        x = '\n\ntook '+ str(stime) + ' seconds\n'
        x += out.getvalue()
        return result, x

Aaron Swartz (aaronsw) on 2009-02-04
Changed in webpy:
assignee: nobody → anandology
status: New → Confirmed
Changed in webpy:
importance: Undecided → Low
milestone: none → 0.33
Anand Chitipothu (anandology) wrote :
Changed in webpy:
status: Confirmed → Fix Committed
Changed in webpy:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers