Add catching of CTRL_BREAK_EVENT signal on Windows OS by filipbuda · Pull Request #6244 · Genymobile/scrcpy (original) (raw)

If a scrcpy process is spawned using Python 3.8.10 with scrcpy v3.3.1 on Windows 10 OS as follows:

proc = subprocess.Popen( "scrcpy --no-window --record=file.mp4", creationflags=subprocess.CREATE_NEW_PROCESS_GROUP )

and the process is terminated as follows:

proc.send_signal(signal.CTRL_BREAK_EVENT)

Then the process will not terminate gracefully and the recording file will be corrupted.

This can be fixed by adding the catching of the CTRL_BREAK_EVENT signal to the windows_ctrl_handler function in scrcpy.c
The fix was tested on a Samsung Galaxy S6 Edge+. The following script:

import signal import subprocess import time

if name == "main": proc = subprocess.Popen( "scrcpy --no-window --record=file.mp4", creationflags=subprocess.CREATE_NEW_PROCESS_GROUP ) time.sleep(10) proc.send_signal(signal.CTRL_BREAK_EVENT) proc.wait()

was run using scrcpy v3.3.1 and the resulting recording file was corrupted. The same script was run using the PR build and the resulting recording file was not corrupted.

Possibly fixes the below issue:
#5195