Skip to content

Commit 9ae477f

Browse files
committed
Better handlinng of Ctrl+C
1 parent a382f2a commit 9ae477f

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

ML/server.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import BaseHTTPServer
22
import subprocess
3+
import sys
34

45
MUNTA_PATH = "./munta"
56
PORT = 3069
67

8+
79
def run_munta(query):
8-
p = subprocess.Popen([MUNTA_PATH], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
10+
p = subprocess.Popen([MUNTA_PATH, '-s'],
11+
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
912
return p.communicate(input=query)
1013

14+
1115
class handler(BaseHTTPServer.BaseHTTPRequestHandler):
1216
def _set_headers(self):
1317
self.send_response(200)
@@ -25,9 +29,17 @@ def do_POST(self):
2529
self._set_headers()
2630
self.wfile.write(run_munta(post_data)[0])
2731

32+
2833
def run(server_class=BaseHTTPServer.HTTPServer, handler_class=handler):
2934
server_address = ('', PORT)
3035
httpd = server_class(server_address, handler_class)
3136
httpd.serve_forever()
3237

33-
run()
38+
39+
if __name__ == "__main__":
40+
print("Server started.")
41+
try:
42+
run()
43+
except KeyboardInterrupt:
44+
print("Server shutting down.")
45+
sys.exit(0)

0 commit comments

Comments
 (0)