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!
|