Closed georgy7 closed 2 months ago
I have written the completion procedure well in the rawvideo_pipe
branch: fcb81089b55d3176041543f664b4bb4dbddf9dbd
You do not need to send SIGTERM to the subprocess. This happens automatically, unless you use signal.SIG_IGN in preexec_fn: https://stackoverflow.com/a/13737455
Therefore, for a graceful shutdown, it was only necessary to carefully complete the threads.
However, it seems, in Windows, the process termination is completely broken.
Sending any signal (except for two) simply kills the process. Calling process.terminate()
also leaves the process no chance to process the termination signal.
On Windows, SIGTERM is an alias for terminate().
terminate() On Windows the Win32 API function TerminateProcess() is called to stop the child.
The TerminateProcess function is used to unconditionally cause a process to exit. A process cannot prevent itself from being terminated.
Those signals that trigger in the expected way are CTRL_C_EVENT and CTRL_BREAK_EVENT. However, they surprisingly work for the parent process as well. What? https://stackoverflow.com/questions/58455684/ctrl-c-event-sent-to-child-process-kills-parent-process
So here's the only way I've found that it seems to work. Sleep is needed so as not to wrap everything around in try-catch, because the signal arrives at the parent process with a slight delay.
try:
os.kill(process.pid, signal.CTRL_C_EVENT)
sleep(0.1)
except KeyboardInterrupt:
pass
If you send a termination signal to the catframes process, FFmpeg continues to run for about a second after the catframes process terminates. Because of this, the file remains locked even if we waited for the process to complete. And we can't delete it.
FFmpeg termination is the responsibility of
catframes.py
. It must not exit earlier.Platform: Win10 Version: bdbae4e5c872d8952cf29a56b086aa84d3411840
Related tasks:
29
30