This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: loogger module locks
Type: Stage:
Components: Library (Lib) Versions: Python 2.4
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: cfuller, vinay.sajip
Priority: normal Keywords:

Created on 2005-11-27 23:31 by cfuller, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg26929 - (view) Author: Chris Fuller (cfuller) Date: 2005-11-27 23:31
I have an application that uses the logger
functionality, and the RotatingFileHandler class. If my
application is running, and another instance is
launched, it fails at the rollover step. I don't want
multiple instances running at once, so this is fine,
and even general, since the rollover must occur if an
instance is already running.

Rather than checking for a generic I/O error, however,
I'd like to use some sort of locking mechanism that is
less opaque. The locking provided won't work, since it
is blocking only: the application deadlocks if one ias
runnning already. Why doesn't it work like a normal
Lock() instance and take a blocking parameter?

I could use locking via the portalocker module from the
python cookbook (hmm, portable file locking would be a
nice thing to have in the standard library, the logger
module already does it anyway!) but I can't find anyway
to access the file descriptor!

Sure, I could workaround that. I could create a
RotatingFileHandler instance, roll over, close it, open
the file, pass it to StreamHandler, but python is way
more elegant than that.

For now, I'll just trap the rollover. Still very cool
stuff!
msg26930 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2005-12-15 09:06
Logged In: YES 
user_id=308438

Closing, as this does not appear to be a bug report.

Thanks for your comments. My advice (if you have multiple
processes logging to the same file) is to add a separate
logging process (or perhaps a thread in one of the
processes) which receives logging events from a socket and
logs to files. This way, there is no contention for the file.

See http://docs.python.org/lib/network-logging.html
History
Date User Action Args
2022-04-11 14:56:14adminsetgithub: 42631
2005-11-27 23:31:17cfullercreate