3
3
import signal
4
4
import sys
5
5
import click
6
- from dotenv import load_dotenv
7
6
import uvicorn
8
7
import threading
9
8
import time
10
9
10
+ from dotenv import load_dotenv
11
11
from openagent .agent .agent import OpenAgent
12
12
from openagent .api .app import app , set_agent
13
13
@@ -41,6 +41,24 @@ def check_exit_windows(loop):
41
41
time .sleep (1 )
42
42
43
43
44
+ def check_exit_unix (loop ):
45
+ """Check for exit command on Unix (press 'q' to quit)"""
46
+ print ("\n Press 'q' to quit..." )
47
+ while True :
48
+ try :
49
+ # Non-blocking read from stdin
50
+ import select
51
+
52
+ if select .select ([sys .stdin ], [], [], 0 )[0 ]:
53
+ key = sys .stdin .read (1 )
54
+ if key == "q" :
55
+ print ("\n Shutting down..." )
56
+ os ._exit (0 )
57
+ except Exception as e :
58
+ print (f"Error reading input: { e } " )
59
+ time .sleep (1 )
60
+
61
+
44
62
@click .group ()
45
63
def cli ():
46
64
"""OpenAgent CLI tool"""
@@ -63,6 +81,7 @@ def start(file, host, port):
63
81
loop = asyncio .new_event_loop ()
64
82
asyncio .set_event_loop (loop )
65
83
84
+ # Set platform specific handlers
66
85
if sys .platform == "win32" :
67
86
signal .signal (signal .SIGINT , win_handler )
68
87
check_exit_func = check_exit_windows
@@ -73,6 +92,8 @@ def start(file, host, port):
73
92
loop .add_signal_handler (
74
93
signal .SIGTERM , lambda : asyncio .create_task (shutdown (agent , loop ))
75
94
)
95
+ check_exit_func = check_exit_unix
96
+
76
97
# Create FastAPI config
77
98
config = uvicorn .Config (app , host = host , port = port , loop = loop )
78
99
server = uvicorn .Server (config )
0 commit comments