Stop processing file during long process

Started by Curtis, October 18, 2014, 08:34:59 PM

Previous topic - Next topic

Curtis

I have exiftool running as a separate process in my vb.net program using -stay_open and feeding commands via stdinp and getting output via stdout.  Occasionally I give exiftool a big .xml file (8mb), since .xml files are in the recognized file extensions list.  For exiftool to process this file (using the -q -X -t commands) can (understandably) take over 5 minutes.  So at some point I'd like to be able to cleanly stop exiftool from further processing of the file.  I can just kill the exiftool process and then restart it, but I was hoping for a better way. 

I was wondering if while exiftool is 'busy' does it still occasionally  check stdinp for commands?  If so what command would I send it to say stop processing the file?

Thanks as usual for any help,
Curits

Phil Harvey

Hi Curtis,

ExifTool doesn't check for input while it is processing.  But you can sent it a SIGINT signal and it will respond by cleaning up and exiting immediately.

- 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 ($).

QPRJohn

Curtis

Do you ever use the "backgroundworker" utilty in VB.Net?

I use it for long processes, like sending images via FTP, it can be cancelled by the user during the process.

Would it help your situation?

-John

Curtis

#3
Hi John,

Thanks for the info.  However, what I use is Tasks, which work quite well and have more features than the Background worker.   What I currently do is start about 1 to 4 Tasks each with its own ExitTool.exe process spawned from each of those Tasks.  It is easy to stop the Tasks, and/or Kill the associated ExifTool.exe process.  But, I wanted a 'nice' way to let ExifTool.exe exit cleanly even when it was still processing the last execute command.  From Phil's suggestion I was able to send a Ctrl-C Signal to the ExifTool.exe process and have it terminate gracefully... so all is good!

Thanks again,
Curtis 

FYI.... the VB.Net code to send Ctrl-C to a Process:
  Private Delegate Function ConsoleCtrlDelegate(CtrlType As UInteger) As [Boolean]

    <DllImport("kernel32.dll", SetLastError:=True)>
    Private Shared Function AttachConsole(dwProcessId As UInteger) As Boolean
    End Function

    Private Declare Auto Function FreeConsole Lib "kernel32.dll" () As Boolean

    <DllImport("kernel32.dll")>
    Private Shared Function SetConsoleCtrlHandler(HandlerRoutine As ConsoleCtrlDelegate, Add As Boolean) As Boolean
    End Function

    <DllImport("kernel32.dll")>
    Private Shared Function GenerateConsoleCtrlEvent(dwCtrlEvent As UInteger, dwProcessGroupId As UInteger) As <MarshalAs(UnmanagedType.Bool)> Boolean
    End Function

    Private Const CTRL_C_EVENT As UInteger = 0

    Private Sub StopProgramByIssuingCtrlCEvent(proc As Process)

        '--This does not require the console window to be visible.

        If AttachConsole(CUInt(proc.Id)) Then

            '--Disable Ctrl-C handling for our program

            SetConsoleCtrlHandler(Nothing, True)
            GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0)

            '--Must wait here. If we don't and re-enable Ctrl-C handling below too fast, we might terminate ourselves.

            proc.WaitForExit(2000)

            FreeConsole()

            '--Re-enable Ctrl-C handling or any subsequently started programs will inherit the disabled state.

            SetConsoleCtrlHandler(Nothing, False)
        End If
    End Sub

SarahC

QuoteExifTool doesn't check for input while it is processing.  But you can sent it a SIGINT signal and it will respond by cleaning up and exiting immediately.

Ah! This could be a way out of the problem I have!

Skippy

#5
In ms-access, I am thinking of shelling to Exiftool in a non-blocking way for slow processes such as writing ImageUniqueIDs into photos that do not have them.  This would open an exiftool DOS window which would show the progress of the process (i.e a list of filenames that have been processed).  I am wondering if the user closes the window, does this cause exiftool to exit in a clean way that is equivalent to Ctrl-C or does it just kill the process?  Just closing the window does not seem to break jpeg files but does seem to leave a few jpeg_Temp files around.  That seems fairly harmless.

Phil Harvey

If _exiftool_tmp files are left around then ExifTool was killed, not terminated nicely.  It will delete the temporary files if it is terminated with CTRL-C.  But unless you are using the -overwrite_original_in_place option, killing ExifTool won't result in any broken files.

- 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 ($).