Missing XMP data causes library to hang indefinitely
Hi there,
I've attached the gif I noticed this behavior on:
I'm running this on Arch Linux, with Exiftool 12.93
This is the line that gets hung: https://github.com/sylikc/pyexiftool/blob/e54f96cd75758096f72bc97c42390f1f9fef8010/exiftool/exiftool.py#L132
Quick repro:
with exiftool.ExifToolHelper() as et:
et.get_tags(["file.gif"], {"tags": ["ExifTool:ExifToolVersion"]})
This then hangs until manually interrupted.
When running the same using exiftool directly, it returns without issue:
$> exiftool -j -G -GIF:GIFVersion file.gif
[{
"SourceFile": "file.gif",
"GIF:GIFVersion": "89a"
}]
When requesting a tag that doesn't exist directly using exiftool, some warnings are printed, but otherwise everything works as expected:
$> exiftool -j -G -AllDates file.gif
Warning: [minor] Empty XMP - file.gif
[{
"SourceFile": "file.gif"
}]
Interestingly enough, when requesting all metadata fields, rather than specific tags, then the library works as expected:
with exiftool.ExifToolHelper() as et:
et.get_metadata(["file.gif"])
By loosely looking through the code, I could see that there's a 30 second timeout once terminate has been called. It would be great to have a general user-specified timeout option for the whole command so that this can be adjusted to match a user's usecase.
Is it actually hanging at select(). Did you turn on logging to see exactly where it hangs up https://sylikc.github.io/pyexiftool/faq.html#i-m-getting-an-error-how-do-i-debug-pyexiftool-output
The terminate timeout doesn't affect Linux typically, though there was that Windows hanging bug that is still semi-fixed in Python 3.12
I'd have to set up a Linux environment to test your exact case with files... if it hangs on select, it's likely there's either something weird about the metadata in the file, or pyexiftool is trying to read an empty file descriptor, which causes the block
This is what I get with debug logging enabled:
INFO:root:Property 'executable': set to "/usr/bin/vendor_perl/exiftool"
INFO:root:Property 'common_args': set to "['-G', '-n']"
INFO:root:Property 'config_file': set to "None"
INFO:root:Method 'execute': Command sent = [b'-ver', b'-echo4', b'=${status}=post149644']
DEBUG:root:ExifToolHelper.execute: IN params = ('-ver',)
DEBUG:root:ExifToolHelper.execute: OUT stdout = "12.96
"
DEBUG:root:ExifToolHelper.execute: OUT stderr = ""
DEBUG:root:ExifToolHelper.execute: OUT status = 0
INFO:root:Method 'run': Exiftool version '12.96' (pid 197187) launched with args '['/usr/bin/vendor_perl/exiftool', '-stay_open', 'True', '-@', '-', '-common_args', '-G', '-n']'
INFO:root:Method 'execute': Command sent = [b'-j', b'-AllDates', b'50177829_758791611162571_747905689162088448_n_2325634544321502.gif', b'-echo4', b'=${status}=post511294']
Full repro code in case I'm using the library wrong: https://gist.github.com/ninas/79cd2fdd476d64b468145aedbf69dbc0
Using trusty print statements in the library code, I can see that it gets stuck here: https://github.com/sylikc/pyexiftool/blob/e54f96cd75758096f72bc97c42390f1f9fef8010/exiftool/exiftool.py#L132
Let me know if there's anything extra you'd like me to try. It does work fine when using exiftool directly, so I don't know that it's something fundamentally broken about the file itself.