RotatingFileHandler Fails

nac cookfitz at
Sat Mar 3 12:42:25 CET 2012

The RotatingFileHandler running on win 7 64-bit; py 2.7 is failing
when the script launches a process using subprocess.Popen. Works fine
if the subprocess is not launched

The exception thrown
Traceback (most recent call last):
  File "C:\Python27\lib\logging\", line 78, in emit
  File "C:\Python27\lib\logging\", line 141, in doRollover
    os.rename(self.baseFilename, dfn)
WindowsError: [Error 32] The process cannot access the file because it
is being used by another process

Anyone have an idea how to fix this?

import os, sys
import logging
import logging.handlers
import subprocess

def chomp(s):
      "remove trailing carriage return"
      if s[-1:]=='\n': return s[:-1]
      else: return s

logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %
(name)-2s %(levelname)-8s %(threadName)-12s %(message)s')
q5Logger = logging.getLogger('Q5')
logFileHandler = logging.handlers.RotatingFileHandler(filename='c:\
\logger\\q5.log', mode= 'a', maxBytes=100, backupCount=5)
logFileHandler.setFormatter(logging.Formatter('%(asctime)s %(name)-2s %
(levelname)-8s %(threadName)-12s %(message)s'))

progOutput = subprocess.Popen(r'dir *.*', shell=True, bufsize=1000,
line = progOutput.readline()
while (line) != "": chomp(line))
      line = progOutput.readline()
rc = progOutput.close()

More information about the Python-list mailing list