You need to check a small module that collects metadata about uploaded files and writes it to a log. The current external contract must be preserved: Python 3.12, CPython, standard library only. The code runs both as a regular module and as an asyncio.run(...) script. It is expected that, on repeated calls, the state of different objects will not get mixed together, and the temporary file will always be closed after writing, even if writing is interrupted by an error. You are allowed to change only the contents of the files from the set below. Reproduction: create two handler instances, add different paths, then invoke writing; separately, simulate an exception during writing and ensure that the file descriptor does not remain open.
CPython 3.12.0; standard library only; execution mode: module import + asyncio.run; no third-party packages; OS assumptions: POSIX-like and Windows are both acceptable, but tests must not rely on platform-specific path separators.
Use line comments to explain the problem, its impact, the fix and how to test it.