This fix worked for me, thanks a lot Ben! I'm off to profiling my
website...

I'll report this as a bug to web.py, using your description:

https://bugs.launchpad.net/webpy/+bug/325139

On Feb 3, 12:35 pm, Ben Corneau <[email protected]> wrote:
> 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.
>
> http://docs.python.org/library/tempfile.html#tempfile.NamedTemporaryFile
> ...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
> imported
>         temp = tempfile.mkstemp()
>         os.close(temp[0])
>         temp_filename = temp[1]
>         prof = hotshot.Profile(temp_filename)
>
>         stime = time.time()
>         result = prof.runcall(self.func, *args)
>         stime = time.time() - stime
>         prof.close()
>
>         import cStringIO
>         out = cStringIO.StringIO()
>         stats = hotshot.stats.load(temp_filename)
>
>         #delete the temp file as son as we are done with it
>         os.remove(temp_filename)
>
>         stats.stream = out
>         stats.strip_dirs()
>         stats.sort_stats('time', 'calls')
>         stats.print_stats(40)
>         stats.print_callers()
>
>         x =  '\n\ntook '+ str(stime) + ' seconds\n'
>         x += out.getvalue()
>
>         return result, x
>
> asmo wrote:
> > OK, I guess this is what needs to be done:
>
> > ---
> > if __name__ == "__main__":
> >    app.run( web.http.profiler )
> > ---
>
> > Testing this on my Vista (ouch) machine I get this error, I guess this
> > is related to my environment:
>
> > ---
> > Traceback (most recent call last):
> >   File "c:\Python25\lib\site-packages\web\wsgiserver\__init__.py",
> > line 1174, in communicate
> >     req.respond()
> >   File "c:\Python25\lib\site-packages\web\wsgiserver\__init__.py",
> > line 544, in respond
> >     self._respond()
> >   File "c:\Python25\lib\site-packages\web\wsgiserver\__init__.py",
> > line 556, in _respond
> >     response = self.wsgi_app(self.environ, self.start_response)
> >   File "c:\Python25\lib\site-packages\web\httpserver.py", line 201, in
> > __call__
> >     return self.app(environ, xstart_response)
> >   File "c:\Python25\Lib\site-packages\web\http.py", line 132, in
> > profile_internal
> >     out, result = profile(app)(e, o)
> >   File "c:\Python25\Lib\site-packages\web\utils.py", line 736, in
> > __call__
> >     prof = hotshot.Profile(temp.name)
> >   File "c:\Python25\lib\hotshot\__init__.py", line 13, in __init__
> >     logfn, self.lineevents, self.linetimings)
> > IOError: [Errno 13] Permission denied: 'c:\\users\\asmo\\appdata\\local
> > \\temp\\tmpnimxms'
> > ---
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to