Skip to content

Commit

Permalink
Merge pull request #48 from brad-colbert/server_clean_ctrl_c
Browse files Browse the repository at this point in the history
v1.2.17: Server exits with ctrl-c
  • Loading branch information
brad-colbert authored Mar 18, 2024
2 parents f054ccf + e78aa71 commit ab08d97
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
21 changes: 18 additions & 3 deletions server/yailsrv.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from pprint import pprint
from PIL import Image
import numpy as np
import sys
#import asyncio

GRAPHICS_8 = 2
Expand Down Expand Up @@ -358,18 +359,32 @@ def handle_client_connection(client_socket):
client_socket.close()
#loop.close() # Close the loop when done

import signal
def handler(signum, frame):
print('SIGINT: Exiting...')
sys.exit(1)

signal.signal(signal.SIGINT, handler)

def main():
connections = 0
threads = []
while True:
client_sock, address = server.accept()
print('Accepted connection from {}:{}'.format(address[0], address[1]))
client_handler = threading.Thread(
target=handle_client_connection,
args=(client_sock,) # without comma you'd get a... TypeError: handle_client_connection() argument after * must be a sequence, not _socketobject
)
connections += 1
client_handler.daemon = True
client_handler.start()
print('Connections:', connections)
threads.append(client_handler)
print('Connections:', len(threads))
'''
try:
except KeyboardInterrupt:
print("Ctrl+C pressed...")
sys.exit(1)
'''

if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

#define MAJOR_VERSION 1
#define MINOR_VERSION 2
#define BUILD_VERSION 16
#define BUILD_VERSION 17

#endif // YAIL_VERSION_H

0 comments on commit ab08d97

Please sign in to comment.