diff --git a/Cargo.lock b/Cargo.lock index 98d664837..7df7e4825 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1212,7 +1212,7 @@ checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" [[package]] name = "robyn" -version = "0.16.1" +version = "0.16.3" dependencies = [ "actix", "actix-files", diff --git a/Cargo.toml b/Cargo.toml index e1cfae178..843aa3464 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "robyn" -version = "0.16.1" +version = "0.16.3" authors = ["Sanskar Jethi "] edition = "2018" description = "A web server that is fast!" diff --git a/pyproject.toml b/pyproject.toml index c63a8c410..405b2ffc8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ name = "robyn" -version = "0.16.1" +version = "0.16.3" description = "A web server that is fast!" authors = ["Sanskar Jethi "] diff --git a/robyn/__init__.py b/robyn/__init__.py index ff760a150..8c623cf5f 100644 --- a/robyn/__init__.py +++ b/robyn/__init__.py @@ -104,6 +104,7 @@ def start(self, url="127.0.0.1", port=5000): """ if not self.dev: + processes = [] workers = self.workers socket = SocketHeld(url, port) for _ in range(self.processes): @@ -122,8 +123,16 @@ def start(self, url="127.0.0.1", port=5000): ), ) p.start() + processes.append(p) print("Press Ctrl + C to stop \n") + try: + for process in processes: + process.join() + except KeyboardInterrupt: + print(f"\n{Colors.BOLD}{Colors.OKGREEN} Terminating server!! {Colors.ENDC}") + for process in processes: + process.kill() else: event_handler = EventHandler(self.file_path) event_handler.start_server_first_time() diff --git a/robyn/processpool.py b/robyn/processpool.py index cd457226c..a1330c42e 100644 --- a/robyn/processpool.py +++ b/robyn/processpool.py @@ -75,5 +75,9 @@ def spawn_process( web_socket.methods["message"], ) - server.start(socket, workers) - asyncio.get_event_loop().run_forever() + try: + server.start(socket, workers) + loop = asyncio.get_event_loop() + loop.run_forever() + except KeyboardInterrupt: + loop.close() diff --git a/robyn/responses.pyi b/robyn/responses.pyi index fc7da4a99..adade8874 100644 --- a/robyn/responses.pyi +++ b/robyn/responses.pyi @@ -9,11 +9,11 @@ def static_file(file_path: str) -> dict[str, Any]: pass -def jsonify(input_dict: dict) -> str: +def jsonify(input_dict: object) -> str: """ This function serializes input dict to a json string - :param input_dict dict: response of the function + :param input_dict object: response of the function """ pass diff --git a/robyn/robyn.pyi b/robyn/robyn.pyi index 295e63f06..fd4d0de74 100644 --- a/robyn/robyn.pyi +++ b/robyn/robyn.pyi @@ -9,7 +9,7 @@ class SocketHeld: pass class Server: - def __init__(self): + def __init__(self) -> None: pass def add_directory( self, @@ -17,9 +17,9 @@ class Server: directory_path: str, index_file: Optional[str], show_files_listing: bool, - ): + ) -> None: pass - def add_header(self, key: str, value: str): + def add_header(self, key: str, value: str) -> None: pass def add_route( self, @@ -28,7 +28,7 @@ class Server: handler: Callable, is_async: bool, number_of_params: int, - ): + ) -> None: pass def add_middleware_route( self, @@ -37,11 +37,11 @@ class Server: handler: Callable, is_async: bool, number_of_params: int, - ): + ) -> None: pass - def add_startup_handler(self, handler: Callable, is_async: bool): + def add_startup_handler(self, handler: Callable, is_async: bool) -> None: pass - def add_shutdown_handler(self, handler: Callable, is_async: bool): + def add_shutdown_handler(self, handler: Callable, is_async: bool) -> None: pass def add_web_socket_route( self, @@ -49,7 +49,7 @@ class Server: connect_route: Tuple[Callable, bool, int], close_route: Tuple[Callable, bool, int], message_route: Tuple[Callable, bool, int], - ): + ) -> None: pass - def start(self, socket: SocketHeld, workers: int): + def start(self, socket: SocketHeld, workers: int) -> None: pass diff --git a/robyn/ws.pyi b/robyn/ws.pyi index 4d5452a9f..efd699fc9 100644 --- a/robyn/ws.pyi +++ b/robyn/ws.pyi @@ -5,5 +5,5 @@ class WS: def __init__(self, robyn_object: Robyn, endpoint: str) -> None: pass - def on(self, type: str): + def on(self, type: str) -> None: pass