From 8eb015e85a72aa29a79966843f8bbfcdad21f8c4 Mon Sep 17 00:00:00 2001 From: Brad Colbert Date: Mon, 18 Mar 2024 08:13:41 -0700 Subject: [PATCH 1/3] Committing to test on Linux --- server/yailsrv.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/server/yailsrv.py b/server/yailsrv.py index cb6d294..ed249ba 100644 --- a/server/yailsrv.py +++ b/server/yailsrv.py @@ -16,6 +16,7 @@ from pprint import pprint from PIL import Image import numpy as np +import sys #import asyncio GRAPHICS_8 = 2 @@ -358,8 +359,16 @@ def handle_client_connection(client_socket): client_socket.close() #loop.close() # Close the loop when done +import signal +def handler(signum, frame): + res = input("Ctrl-c was pressed. Do you really want to exit? y/n ") + if res == 'y': + 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])) @@ -367,9 +376,16 @@ def main(): 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() From f306cedc4472a8bbf551f0389fb4b24b6855e772 Mon Sep 17 00:00:00 2001 From: Brad Colbert Date: Mon, 18 Mar 2024 09:26:56 -0700 Subject: [PATCH 2/3] Added a SIGINT handler to yailsrv to catch and exit the application. Ctr-C should do it or kill -2 pid should as well. --- server/yailsrv.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) mode change 100644 => 100755 server/yailsrv.py diff --git a/server/yailsrv.py b/server/yailsrv.py old mode 100644 new mode 100755 index ed249ba..7c582bd --- a/server/yailsrv.py +++ b/server/yailsrv.py @@ -361,9 +361,8 @@ def handle_client_connection(client_socket): import signal def handler(signum, frame): - res = input("Ctrl-c was pressed. Do you really want to exit? y/n ") - if res == 'y': - sys.exit(1) + print('SIGINT: Exiting...') + sys.exit(1) signal.signal(signal.SIGINT, handler) From e78aa711aa27ac370f5802751d3c41fedb19aefa Mon Sep 17 00:00:00 2001 From: Brad Colbert Date: Mon, 18 Mar 2024 09:29:13 -0700 Subject: [PATCH 3/3] Ticked the version to reflect the changes to the yailsrv. --- src/version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h b/src/version.h index fe63767..7caefb1 100644 --- a/src/version.h +++ b/src/version.h @@ -5,6 +5,6 @@ #define MAJOR_VERSION 1 #define MINOR_VERSION 2 -#define BUILD_VERSION 16 +#define BUILD_VERSION 17 #endif // YAIL_VERSION_H