Crosswalk Cementerio de Trenes de Uyuni Llamas, Alpacas and Mutants Mardi Himal Trail The Danube at Night Fog Rolling In Resting Pisac Hillside Machhapuchhre Vocano Scarred Mountains Prepping to FIght Twilight Fog Monument Valley Market Flags Headfirst Annapurna South Bluebird Skies Annapurna South Under the Stars Chinchero at Sunset Zabriskie Point Photographers Green River Canyons at Sunrise Sheepherders and Annapurna South Rolling Fog Sunset From Moro Rock Fish Market Temple Statue Old Man in Siding Sand Dunes Very rare deserted street The Blue Mosque Grafitti Zabriskie Point Marin Headlands The Golden Gate at Night The Buttermilks Buildings and a Bridge Cropped Prayer Flags Bay Area Sunrise Sunset from Marshall Beach, SF Sunset Phewa Boats Boudhanath Stupa Stars Over Annapurna South Eastern Sierras Under Shadow Cumhuriyet Anıtı Yosemite Fall Leaves Rooster Fights at Forest Camp Half Dome at Sunset SF Cable Car Route Golden Gate Night Cats Annapurna South in the Early Morning Snow and Shadows Mardi Himal Trail Half Dome at Sunset Bodie White Mountains Sunset Alamo Square Hong Kong from the Peak Fall Colors

Python virtualenvwrapper and Logging

January 20, 2011 —

I ran into this issue, and couldn't find a resolution anywhere online. Well, I figured it out, and thought that I'd put it online for others to find.

The issue was that I got exception tracebacks when sourcing the /usr/local/bin/virtualenvwrapper.sh script upon bash initialization. However, the exception happens while Python is running it's atexit handlers. So the stack was only 3 levels deep. I'm running virtualenv and virtualenvwrapper on my Ubuntu 9.04 server.

Here's the output of the exception that I got:

[streeter@mail]:~$ source /usr/local/bin/virtualenvwrapper.sh
Traceback (most recent call last):
File "/usr/lib/python2.6/logging/handlers.py", line 72, in emit
self.doRollover()
File "/usr/lib/python2.6/logging/handlers.py", line 129, in doRollover
os.rename(self.baseFilename, dfn)
OSError: [Errno 13] Permission denied
Traceback (most recent call last):
File "/usr/lib/python2.6/logging/handlers.py", line 71, in emit
if self.shouldRollover(record):
File "/usr/lib/python2.6/logging/handlers.py", line 145, in shouldRollover
self.stream.seek(0, 2) #due to non-posix-compliant Windows feature
ValueError: I/O operation on closed file
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "/usr/lib/python2.6/atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
File "/usr/lib/python2.6/logging/__init__.py", line 1508, in shutdown
h.flush()
File "/usr/lib/python2.6/logging/__init__.py", line 754, in flush
self.stream.flush()
ValueError: I/O operation on closed file
Error in sys.exitfunc:
Traceback (most recent call last):
File "/usr/lib/python2.6/atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
File "/usr/lib/python2.6/logging/__init__.py", line 1508, in shutdown
h.flush()
File "/usr/lib/python2.6/logging/__init__.py", line 754, in flush
self.stream.flush()
ValueError: I/O operation on closed file
[streeter@mail]:~$

As you can see, not a lot to go with. So it seems that virtualenvwrapper does some logging, and it looks like the logging module wants to rename that logfile. Digging even deeper, the logging module wants to rotate the logfile because it got too big. Well, where is the log file? Turns out that virtualenvwrapper sets up a logfile called hook.log at the root of the WORKON_HOME environment variable. My WORKON_HOME is set to /usr/local/pythonenv and lo and behold, that directory was not writeable by my logged in user. Thats an easy fix. Just change the permissions.