Created
February 5, 2023 12:55
-
-
Save ZhymabekRoman/040bcc13b933296599b4d427c1bab5d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import signal | |
import os | |
import sys | |
def msg(text: str) -> None: | |
print(f"::notice::{text}") | |
if len(sys.argv) == 0: | |
msg("No args!") | |
cmd = sys.argv[1:] | |
timeout_second = 25 | |
lock_file = ".parted_executing_success" | |
if os.path.isfile(lock_file): | |
msg("Task already finished") | |
sys.exit() | |
try: | |
msg("Task start") | |
msg(f"cmd: {cmd}") | |
proc = subprocess.Popen(cmd) | |
outs, errs = proc.communicate(timeout=timeout_second) | |
except subprocess.TimeoutExpired: | |
msg("Task timeouted") | |
os.kill(proc.pid, signal.SIGINT) | |
outs, errs = proc.communicate() | |
else: | |
msg("Task done") | |
with open(lock_file, "w") as file: | |
file.write("") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment