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.

Author ankostis
Recipients ankostis, penlect, vinay.sajip
Date 2020-08-05.06:06:13
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1596607573.95.0.247308930011.issue41483@roundup.psfhosted.org>
In-reply-to
Content
The `logging.handlers.MemoryHandler.flush()` method acquire the lock even if target has not been set, and the method is a noop:

```
def flush(self):
    # (Docstring skipped)
    self.acquire()
    try:
        if self.target:
	    for record in self.buffer:
	        self.target.handle(record)
	    self.buffer..clear()
    finally:
        self.release()
```

An optimized version would re-arrrange the nesting to avoid the locking:

```
def flush(self):
    # (Docstring skipped)
    if self.target:
        self.acquire()
        try:
            for record in self.buffer:
                self.target.handle(record)
            self.buffer.clear()
        finally:
            self.release()
```

- There is no use-case, beyond the expected performance gain.
- Without having searched, i would deem highly improbable the existence of code in the std-library or 3rdp code that depends on the current noop-locking when `flush()` is called.
History
Date User Action Args
2020-08-05 06:06:14ankostissetrecipients: + ankostis, vinay.sajip, penlect
2020-08-05 06:06:13ankostissetmessageid: <1596607573.95.0.247308930011.issue41483@roundup.psfhosted.org>
2020-08-05 06:06:13ankostislinkissue41483 messages
2020-08-05 06:06:13ankostiscreate