Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #21226

Re: RotatingFileHandler Fails

Path csiph.com!usenet.pasdenom.info!gegeweb.org!newsfeed.kamp.net!newsfeed.kamp.net!newsfeed.freenet.ag!news2.euro.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <prvs=4044facd4=jeanmichel@sequans.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'socket': 0.04; 'sys': 0.05; 'failing': 0.09; 'skip:\\ 10': 0.09; 'subprocess': 0.09; 'thrown': 0.09; 'trailing': 0.09; 'exception': 0.12; 'server,': 0.12; 'def': 0.13; '2.7': 0.13; '"remove': 0.16; 'logger.': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.18; 'this?': 0.19; '(most': 0.21; 'cc:no real name:2**0': 0.21; 'file,': 0.21; 'header:In-Reply-To:1': 0.22; 'opens': 0.23; 'operand': 0.23; 'fine': 0.24; 'traceback': 0.24; 'fix': 0.25; 'mode': 0.25; 'cc:2**0': 0.26; 'import': 0.27; 'skip:" 30': 0.28; 'script': 0.28; 'cc:addr:python.org': 0.29; 'operation.': 0.30; 'os,': 0.30; 'skip:% 10': 0.30; 'error': 0.30; 'file.': 0.31; 'skip:l 30': 0.32; 'thread': 0.32; 'anyone': 0.32; 'idea': 0.32; "won't": 0.33; 'header:User-Agent:1': 0.33; 'message.': 0.33; 'file': 0.34; 'running': 0.34; 'last):': 0.34; 'but': 0.37; 'using': 0.37; 'another': 0.37; 'bunch': 0.38; 'could': 0.38; 'some': 0.38; 'think': 0.38; 'skip:o 20': 0.38; 'open': 0.38; 'cannot': 0.39; 'being': 0.40; 'bring': 0.61; 'your': 0.61; 'happen': 0.61; 'processes,': 0.67; '"":': 0.84; '[error': 0.84; 'launches': 0.84; 'skip:q 30': 0.84; '78,': 0.91
X-IronPort-AV E=Sophos;i="4.73,533,1325458800"; d="scan'208";a="213093"
X-Virus-Scanned amavisd-new at zimbra.sequans.com
Date Mon, 05 Mar 2012 11:27:50 +0100
From Jean-Michel Pichavant <jeanmichel@sequans.com>
User-Agent Mozilla-Thunderbird 2.0.0.24 (X11/20100328)
MIME-Version 1.0
To nac <cookfitz@gmail.com>
Subject Re: RotatingFileHandler Fails
References <e236bc14-14c4-4574-a0dd-68c8db74a700@p6g2000yqi.googlegroups.com>
In-Reply-To <e236bc14-14c4-4574-a0dd-68c8db74a700@p6g2000yqi.googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.400.1330943283.3037.python-list@python.org> (permalink)
Lines 58
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1330943283 news.xs4all.nl 6895 [2001:888:2000:d::a6]:36155
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:21226

Show key headers only | View raw


nac wrote:
> 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\handlers.py", line 78, in emit
>     self.doRollover()
>   File "C:\Python27\lib\logging\handlers.py", 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'))
> logFileHandler.setLevel(logging.DEBUG)
> q5Logger.addHandler(logFileHandler)
>
> progOutput = subprocess.Popen(r'dir *.*', shell=True, bufsize=1000,
> stdout=subprocess.PIPE).stdout
> line = progOutput.readline()
> while (line) != "":
>       q5Logger.info( chomp(line))
>       line = progOutput.readline()
> rc = progOutput.close()
>   
I don't think you can open a file from 2 different processes, hence the 
error message. The only exception would be that one of them opens it in 
read only mode which won't happen for log file.

You cannot fix it, it is the operand system that blocks the operation.
Using thread may allow you to log into the same file, but could bring a 
bunch of other problems.

I know some ppl use a log server, your processes using a socket (client) 
logger. You could do that on your local machine. There's a tutorial on 
that in the logging documentation.

JM

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

RotatingFileHandler Fails nac <cookfitz@gmail.com> - 2012-03-03 03:42 -0800
  Re: RotatingFileHandler Fails Jean-Michel Pichavant <jeanmichel@sequans.com> - 2012-03-05 11:27 +0100
    Re: RotatingFileHandler Fails nac <cookfitz@gmail.com> - 2012-03-05 18:17 -0800
      Re: RotatingFileHandler Fails arun1 <arun.sathyan@ust-global.com> - 2012-03-07 05:20 -0800
      Re: RotatingFileHandler Fails arun1 <arun.sathyan@ust-global.com> - 2012-03-07 07:33 -0800

csiph-web