Answer the question
In order to leave comments, you need to log in
How to set timeout?
Hello.
There is a process.bat
@ECHO OFF
start /B python script1.py
start /B python script2.py
:LOOP
tasklist | find /i "python.exe" >nul 2>&1
IF ERRORLEVEL 1 (
GOTO CONTINUE
) ELSE (
ECHO script is still running
Timeout /T 5 /Nobreak
GOTO LOOP
)
:CONTINUE
python script3.py
start /B python script2.py /t 600 exit
Answer the question
In order to leave comments, you need to log in
that's strange, you have python scripts, in python there are many ways to organize a controlled subscript execution timeout, but you want cmd \ bat
import subprocess
try:
r = subprocess.run(['python', 'script2'], timeout=5)
except subprocess.TimeoutExpired as e:
print(e)
try:
r = subprocess.run(['python', 'script1'], timeout=50)
except subprocess.TimeoutExpired as e:
print(e)
$p1=start 'python script1.py' -PassThru -NoNewWindow
$p2=start 'python script2.py' -PassThru -NoNewWindow
$p1 | Wait-Process -Timeout 10 -ErrorAction SilentlyContinue -ErrorVariable t1;if ($t2) { $p1 | kill}
$p2 | Wait-Process -Timeout 500 -ErrorAction SilentlyContinue -ErrorVariable t2;if ($t2) { $p2 | kill}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question