Skip to content

Commit

Permalink
1. Gracefully shutdown the server upon keyboard interrupts
Browse files Browse the repository at this point in the history
2. Add wrapper script as a workaround to allow binding optimus on port 53
  • Loading branch information
anchal00 committed Aug 20, 2024
1 parent 4286e48 commit 2832798
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 2 additions & 0 deletions init
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
sudo ~/.pyenv/shims/optimus "$@"
15 changes: 10 additions & 5 deletions optimus/optimus_server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ def run_server(port: int, worker_threads: int):
master_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
master_socket.bind(("0.0.0.0", port))
log(f"Started Optimus Server on Port {port}")
# TODO: Test with ProcessPoolExecutor and EPOLL
with futures.ThreadPoolExecutor(max_workers=worker_threads) as pool:
while True:
received_bytes, address = master_socket.recvfrom(600)
pool.submit(handle_request, master_socket, received_bytes, address)
# TODO: Test with Process PoolExecutor and EPOLL
try:
with futures.ThreadPoolExecutor(max_workers=worker_threads) as pool:
while True:
received_bytes, address = master_socket.recvfrom(600)
pool.submit(handle_request, master_socket, received_bytes, address)
except KeyboardInterrupt:
log("Goodbye ! Shutting Down the server...")
finally:
master_socket.close()

0 comments on commit 2832798

Please sign in to comment.