diff options
author | Victor Stinner <vstinner@python.org> | 2020-11-02 22:17:46 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-02 22:17:46 (GMT) |
commit | 45df61fd2d58e8db33179f3b5d00e53fe6a7e592 (patch) | |
tree | a673a8e89a1c79eab6e9a583c5f221b323e57d2f /Lib/logging | |
parent | 5cf4782a2630629d0978bf4cf6b6340365f449b2 (diff) | |
download | cpython-45df61fd2d58e8db33179f3b5d00e53fe6a7e592.zip cpython-45df61fd2d58e8db33179f3b5d00e53fe6a7e592.tar.gz cpython-45df61fd2d58e8db33179f3b5d00e53fe6a7e592.tar.bz2 |
bpo-26789: Fix logging.FileHandler._open() at exit (GH-23053)
The logging.FileHandler class now keeps a reference to the builtin
open() function to be able to open or reopen the file during Python
finalization.
Fix errors like:
Exception ignored in: (...)
Traceback (most recent call last):
(...)
File ".../logging/__init__.py", line 1463, in error
File ".../logging/__init__.py", line 1577, in _log
File ".../logging/__init__.py", line 1587, in handle
File ".../logging/__init__.py", line 1649, in callHandlers
File ".../logging/__init__.py", line 948, in handle
File ".../logging/__init__.py", line 1182, in emit
File ".../logging/__init__.py", line 1171, in _open
NameError: name 'open' is not defined
Diffstat (limited to 'Lib/logging')
-rw-r--r-- | Lib/logging/__init__.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index 265e286..badfd65 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -1148,6 +1148,10 @@ class FileHandler(StreamHandler): self.encoding = encoding self.errors = errors self.delay = delay + # bpo-26789: FileHandler keeps a reference to the builtin open() + # function to be able to open or reopen the file during Python + # finalization. + self._builtin_open = open if delay: #We don't open the stream, but we still need to call the #Handler constructor to set level, formatter, lock etc. @@ -1183,8 +1187,9 @@ class FileHandler(StreamHandler): Open the current base file with the (original) mode and encoding. Return the resulting stream. """ - return open(self.baseFilename, self.mode, encoding=self.encoding, - errors=self.errors) + open_func = self._builtin_open + return open_func(self.baseFilename, self.mode, + encoding=self.encoding, errors=self.errors) def emit(self, record): """ |