Skip to content

Fix thread safe branch

Rolf Krahl requested to merge RKrahl1/vignette:thread-safe into thread-safe

Add several fixes to the thread-safe branch:

  • Fix usage of threading.local: it is not a submodule that could be imported, but a class that need to be instantiated. Add new class _Python_Magic as a wrapper around the python-magic call that manages the thread local memory to keep the Magic() object.
  • Don't import magic.compat as it is not used anyway.
  • Move the whole logic to find a usable magic library in the present environment out of class ThumbnailBackend into a helper class _Magic.
  • Fix the call of puremagic: need to add a mime=True argument

Note that this implementation explicitly drops support for libmagic's own python bindings. The previous code in branch thread-safe already (inadvertently?) broke it, so this is not a change in practice. If you want to readd libmagic python binding support, you'd need to add yet another helper similar to class _Python_Magic. But then, you'd need to wade your path through libmagic internals, how their Magic() object needs to be called, and these internals are awkward, so I'm not sure if that is worth it.

I also didn't bother to fix the dependencies in pyproject.toml.

Edited by Rolf Krahl

Merge request reports