-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
56 lines (44 loc) · 1.19 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
49
50
51
52
53
54
55
56
import os
import signal
import subprocess
import sys
import time
def start_uvicorn():
os.chdir("app")
return subprocess.Popen(
[
sys.executable,
"-m",
"uvicorn",
"main:app",
"--host",
"0.0.0.0",
"--port",
"8000",
"--reload",
]
)
def start_fetch_agent():
os.chdir("..")
return subprocess.Popen([sys.executable, "sampleAgent/sampleAgent.py"])
def main():
# Start Uvicorn server
uvicorn_process = start_uvicorn()
print("Uvicorn server started.")
time.sleep(5)
# Start Fetch.ai agent
fetch_agent_process = start_fetch_agent()
print("Fetch.ai agent started.")
# Handle termination signals to gracefully shut down both processes
def signal_handler(sig, frame):
print("Terminating processes...")
uvicorn_process.terminate()
fetch_agent_process.terminate()
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
# Wait for processes to complete
uvicorn_process.wait()
fetch_agent_process.wait()
if __name__ == "__main__":
main()