-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
48 lines (42 loc) · 1.28 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import subprocess
import multiprocessing
import argparse
from dotenv import load_dotenv
import os
load_dotenv()
instance_id = os.getenv("instance_id")
# Add the optional argument
# parser.add_argument("-s", "--stop", help="Stop Aws", action="store_true")
# args = parser.parse_args()
# Define a function to run a script
def run_script(script_path):
process = subprocess.Popen(["python", script_path])
process.wait()
return process.returncode
# Define the paths to the scripts to run
script_paths = ["main.py"]
# # Create a pool of worker processes
# pool = multiprocessing.Pool()
# Run the scripts in parallel
# results = pool.map_async(run_script, script_paths)
# Wait for all scripts to finish
# results.wait()
results = []
for script in script_paths:
results.append(run_script(script))
print(results)
# Check the return codes
# return_codes = results.get()
# if all(rc == 0 for rc in return_codes):
if all(rc == 0 for rc in results):
print("All scripts completed successfully")
subprocess.run(
f"aws ec2 stop-instances --instance-ids {instance_id} --region us-east-1",
shell=True,
)
else:
print("One or more scripts failed")
subprocess.run(
f"aws ec2 stop-instances --instance-ids {instance_id} --region us-east-1",
shell=True,
)