[File] [PATCH] python/magic.py: avoid TypeError in del at interpreter shutdown
Vincent Mihalkovic
vmihalko at redhat.com
Tue Feb 10 12:52:56 UTC 2026
Hi,
I am seeing a TypeError at Python interpreter shutdown when using the
Python bindings shipped with file (python/magic.py).
MagicDetect.__del__() calls Magic.close() (see
https://github.com/file/file/blob/master/python/magic.py#L300-L310), which
in turn calls the module-global _close in Magic.close() (see
https://github.com/file/file/blob/master/python/magic.py#L130-L136).
During interpreter shutdown, module globals may already be cleared, so
_close can become None, resulting in: TypeError: ‘NoneType’ object is not
callable
The attached patch avoids relying on the module-global _close during
finalization by caching the magic_close function pointer on the Magic instance
and using that in close(). This prevents the shutdown exception without
changing normal runtime behavior.
Related downstream report:
https://bugzilla.redhat.com/show_bug.cgi?id=2419719
Best regards,
Vincent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.astron.com/pipermail/file/attachments/20260210/d133fc56/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: python-magic.patch
Type: application/octet-stream
Size: 562 bytes
Desc: not available
URL: <https://mailman.astron.com/pipermail/file/attachments/20260210/d133fc56/attachment.obj>
More information about the File
mailing list