Does not works in Python 2.7 (Windows)

Bug #1265150 reported by q88798
22
This bug affects 4 people
Affects Status Importance Assigned to Milestone
Concurrent Log Handler for Python
New
Undecided
Unassigned

Bug Description

The following code from the simple example simply hang:-

from logging import getLogger, INFO
from cloghandler import ConcurrentRotatingFileHandler
import os

log = getLogger()
# Use an absolute path to prevent file rotation trouble.
logfile = os.path.abspath("mylogfile.log")
# Rotate log after reaching 512K, keep 5 old copies.
rotateHandler = ConcurrentRotatingFileHandler(logfile, "a", 512*1024, 5)
log.addHandler(rotateHandler)
log.setLevel(INFO)

log.info("Here is a very exciting log message, just for you") # <-- hang over here

Environment:-
Windows 7
Python 2.7.5 (32-bit)
ConcurrentLogHandler-0.9.1

Revision history for this message
Hemie143 (hemie143) wrote :

Doesn't work in Python 3.4 either.
The log entries aren't flushed and/or it stucks the python script. Probably something isn't released properly.

Are there chances that this will ever be corrected ?

Revision history for this message
Preston Landers (planders) wrote :

The problem is in how the Python logging package acquires locks recursively when it already holds a lock. With the base class's threading lock this is already handled.

I've got a git fork which fixes the problem here:

https://github.com/Preston-Landers/ConcurrentLogHandler

Tested with Python 3.6.0b4 x64 on Windows 10.

The problem is that logging.Handler calls acquire() to emit the message and then calls flush(), which also calls acquire() while the lock is already held, and this causes a deadlock given the locking technique used.

The fix in cloghandler.py is to keep track of the number of recursive acquires() and only do the actual locking or releasing when the stack is size 1.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.