ExifTool on Windows may not terminate the subprocess when wrapper gets killed

Started by sylikc, May 05, 2021, 08:13:06 PM

Previous topic - Next topic

sylikc

Phil, I'm having a very strange issue while developing PyExifTool.  I've been trying to nail it down for weeks but just can't seem to figure out what exactly is happening, or why it happens.

Anyways, the symptoms are as follows.  When PyExifTool starts, one of the tests it does is that, it calls a TerminateProcess() on exiftool.exe that's launched and sees if it is still running.  When called with the standard "-stay_open True -@ -", and nothing has been called to it since starting up, the termination seems to kill the wrapper AND the exiftool.exe below that.  However, if I run any command, say a "-ver", and then do that TerminateProcess(), the exiftool.exe subprocess doesn't terminate with the wrapper.

I tried replicating the interaction using just Windows TASKLIST and TASKKILL and couldn't get the same interaction as it does with the python interpreter, which might be something.  The PyExifTool connects up pipes and stuff so I don't know if data in a pipe might be causing it.

I'm not sure how to write a test case either, short of having you run the PyExifTool tests... it's easily replicated running the tests in PyExifTool.  I even have a batch file for that in the GitHub repository.


(To run the PyExifTool test suite, it's as simple as having Python 3.6+, and exiftool.exe somewhere.  then it's just a batch file, if you'd like to see the thing happen... )

Phil Harvey

You should be terminating the process with -stay_open\nfalse\n

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

sylikc

Phil, right that's the standard way to terminate.  I guess I can remove that test case, but sometimes there's a legitimate reason to go and try to kill the process.

The strange thing is that the test case works fine when no commands have ran, but fail when any command has ran.  It's just a strange interaction between the wrapper and the main process that doesn't happen when just running, or run-and-kill.