-
-
Notifications
You must be signed in to change notification settings - Fork 10.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add time-limit argument #3752
Comments
As a workaround, did you test #818 (comment)? |
Ah yes, it's your last test. Weird, it should work. |
Just to be sure, if you run |
Yes, pressing pressing Ctrl+c from windows terminal does work as expected. Sorry for not mentioning that! |
You can refer to this: In python's subprocess, when sending CTRL+C command for stdin of a specific process ID, it will wait for the process to finish before sending it. Therefore, you should change the pid to 0 and send CTRL_C_EVENT to the parent process in order to achieve the purpose of interrupting the process. os.kill(0, signal.CTRL_C_EVENT)
# ^Here |
Thank you @nnnpa31 ! The following setup is working for me. # demo.py
# this script is launched by wrapper.py
import signal, sys, time, subprocess
def signal_handler(signal, frame):
print('Ctrl+C received in demo.py')
time.sleep(1)
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
print('demo.py started')
proc = subprocess.Popen(["scrcpy", "-Nr", "test.mp4"]) # simple scrcpy command # wrapper.py
import subprocess, time, signal, sys, os
def signal_handler(signal, frame):
print('Ctrl+C received in wrapper.py')
time.sleep(1)
signal.signal(signal.SIGINT, signal_handler)
print("wrapper.py started")
subprocess.Popen("python demo.py")
time.sleep(5) # Run for 5 seconds
os.kill(0, signal.CTRL_C_EVENT) Launching this with This is a nice workaround and it works well enough for me, so I'll close the issue. |
I agree. |
See #4052 |
Related but not solving my issue:
Is your feature request related to a problem? Please describe.
I am trying to automate the acquisition of videos from an android phone which can last for hours.
I know how long the recording should be, so something like
adb screenrecord --time-limit
would be great (see here)Describe the solution you'd like
Something similar to
adb screenrecord --time-limit=S <file>
would be great (see here), whereS
is the amount of time in seconds of the desired recording duration.Describe alternatives you've considered
My automation system is only working on windows, unfortunately.
I tried interrupting the scrcpy process after a fixed amount of time in multiple ways but it is either not stopping or produces a corrupted video file.
Tests:
start /B scrcpy -Nr test.mp4 && timeout /t 5 /nobreak >nul && taskkill /im scrcpy.exe /f
: corrupted fileterminate()
andCTRL_BREAK_EVENT
, process not terminating withCTR_C_EVENT
. In any case, no useful output fileadb shell pkill <adb process pid>
(see What is the best way to interrupt recording (programmable) in Windows? #818 (comment)). Nothing happens.The text was updated successfully, but these errors were encountered: