Timeline for Why would CPython logging use a Lock for each handler rather than one Lock per Logger?
Current License: CC BY-SA 4.0
        6 events
    
    | when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Dec 24, 2018 at 11:13 | vote | accept | Delgan | ||
| Dec 24, 2018 at 11:13 | comment | added | Delgan | And putting your first argument in others words: one lock per handler allows "parallelization" of logs handlings. For example, if using only one lock, if H1 and H2 are both slow, and if two threads need to log a message at the same time, the second thread to acquire the lock will need to wait for the first thread to emit on both H1 and H2, before logging itself to H1 + H2. Using one lock per handler, this allows second thread to emit on H1 as soon as possible, while in the same time, the other thread log to H2. | |
| Dec 24, 2018 at 11:09 | comment | added | Delgan | Oh, yeah, I did not think of the fact that handlers could be re-used across multiple loggers. | |
| Dec 24, 2018 at 10:46 | comment | added | Lie Ryan | Also, locking on the loggers would probably not achieve thread safety as a single handler can be configured as a handle target for multiple loggers. If you lock on the loggers, then multiple threads logging to multiple logger that logs to the same handler will be indeterministic. | |
| Dec 24, 2018 at 10:27 | comment | added | Delgan | 
        
            
    I don't mean using one lock for "the entire logging library", I mean using one lock per logger. If H1 is slow and H2 is fast, but both are attached to the same logger, then H1 will block H2 while doing logger.log() anyway, right?
        
     | 
|
| Dec 24, 2018 at 10:18 | history | answered | Lie Ryan | CC BY-SA 4.0 |