Traceback (most recent call last):
File "logging-error.py", line 22, in <module>
logging.warning("warning msg2")
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
File "/usr/lib/python3.13/logging/__init__.py", line 2180, in warning
root.warning(msg, *args, **kwargs)
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.13/logging/__init__.py", line 1531, in warning
self._log(WARNING, msg, args, **kwargs)
~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.13/logging/__init__.py", line 1664, in _log
self.handle(record)
~~~~~~~~~~~^^^^^^^^
File "/usr/lib/python3.13/logging/__init__.py", line 1680, in handle
self.callHandlers(record)
~~~~~~~~~~~~~~~~~^^^^^^^^
File "/usr/lib/python3.13/logging/__init__.py", line 1736, in callHandlers
hdlr.handle(record)
~~~~~~~~~~~^^^^^^^^
File "/usr/lib/python3.13/logging/__init__.py", line 1026, in handle
self.emit(record)
~~~~~~~~~^^^^^^^^
File "/usr/lib/python3.13/logging/handlers.py", line 539, in emit
self.reopenIfNeeded()
~~~~~~~~~~~~~~~~~~~^^
File "/usr/lib/python3.13/logging/handlers.py", line 529, in reopenIfNeeded
self.stream = self._open()
~~~~~~~~~~^^
File "/usr/lib/python3.13/logging/__init__.py", line 1247, in _open
return open_func(self.baseFilename, self.mode,
encoding=self.encoding, errors=self.errors)
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmpm9g_s9xw/link/file.log'
Bug report
Bug description:
According to the Python docs setting
logging.raiseExceptions = Falseshould cause "exceptions get silently ignored" while logging. In the following snippet aWatchedFileHandleris used on a link to a directory, which gets removed at runtime, causing a FileNotFoundException in the last logging command (see traceback for details below).In my understanding the problem is that while
StreamHandler.emit()correctly callsHandler.handleError()on exceptions, the derived handler classes do not handle exceptions the same way. Thus theFileNotFoundErroris raised from theWatchedFileHandlerimplementation as reported below.IMHO standard handler classes should exhibit behavior consistent with
StreamHandlerand raise no exceptions while logging iflogging.raiseExceptions = Falseis set.Reproducer tested with Python 3.13
Traceback on Ubuntu 25.04
CPython versions tested on:
3.13
Operating systems tested on:
Linux
Linked PRs