Skip to content

Instantly share code, notes, and snippets.

@ZhymabekRoman
Created February 5, 2023 12:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZhymabekRoman/040bcc13b933296599b4d427c1bab5d8 to your computer and use it in GitHub Desktop.
Save ZhymabekRoman/040bcc13b933296599b4d427c1bab5d8 to your computer and use it in GitHub Desktop.
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