New submission from Kostis Anagnostopoulos <ankos...@gmail.com>:
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. ---------- components: Library (Lib) messages: 374859 nosy: ankostis, penlect, vinay.sajip priority: normal severity: normal status: open title: Do not acquire lock in MemoryHandler.flush() if no target defined type: performance versions: Python 3.10, Python 3.9 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue41483> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com