diff --git a/pyproject.toml b/pyproject.toml index 4659521..ec2041e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "smyth" -version = "0.2.0" +version = "0.2.1" description = "" authors = ["Mirumee "] readme = "README.md" diff --git a/src/smyth/__main__.py b/src/smyth/__main__.py index 8eccb74..2227406 100644 --- a/src/smyth/__main__.py +++ b/src/smyth/__main__.py @@ -8,6 +8,7 @@ from smyth.config import get_config, get_config_dict, serialize_config config = get_config(get_config_dict()) + logging_config = { "version": 1, "disable_existing_loggers": False, @@ -16,6 +17,7 @@ "class": "rich.logging.RichHandler", "formatter": "default", "markup": True, + "rich_tracebacks": True, }, }, "formatters": { @@ -32,6 +34,7 @@ logging.config.dictConfig(logging_config) LOGGER = logging.getLogger(__name__) + @click.group() def cli(): pass diff --git a/src/smyth/process.py b/src/smyth/process.py index 120884b..5041e25 100644 --- a/src/smyth/process.py +++ b/src/smyth/process.py @@ -66,11 +66,20 @@ def run(self): def send(self, data) -> RunnerResult | None: LOGGER.info("Sending data to process %s: %s", self.name, data) + if not self.is_alive(): + raise RuntimeError(f"Process '{self.name}' is not alive, restart server.") self.input_queue.put(data) try: - result_data = self.output_queue.get() - LOGGER.info("Received data from process %s: %s", self.name, result_data) - return RunnerResult.model_validate_json(result_data) + while True: + result_data = self.output_queue.get(timeout=10) + if not result_data: + LOGGER.info("Received empty data from process %s, checking if process is alive", self.name) + if not self.is_alive(): + LOGGER.info("Process %s is not alive, breaking", self.name) + break + continue + LOGGER.info("Received data from process %s: %s", self.name, result_data) + return RunnerResult.model_validate_json(result_data) except Empty: return None except KeyboardInterrupt: diff --git a/src/smyth/runner.py b/src/smyth/runner.py index 161bed2..35c9a22 100644 --- a/src/smyth/runner.py +++ b/src/smyth/runner.py @@ -111,7 +111,11 @@ def timeout_handler(signum, frame): def main(lambda_handler_config: HandlerConfig, input_queue: Queue, output_queue: Queue): LOGGER.setLevel(lambda_handler_config.log_level) sys.stdin = open("/dev/stdin") - lambda_handler = import_attribute(lambda_handler_config.handler_path) + try: + lambda_handler = import_attribute(lambda_handler_config.handler_path) + except ImportError as error: + LOGGER.error("Could not import lambda handler: %s", error) + raise coldstart_next_invokation = lambda_handler_config.fake_coldstart_time diff --git a/src/smyth/server.py b/src/smyth/server.py index 3de3c49..8e7b612 100644 --- a/src/smyth/server.py +++ b/src/smyth/server.py @@ -40,6 +40,7 @@ async def lifespan(app: Starlette): process.terminate() process.join() LOGGER.info("All lambda processes terminated") + def get_process_definition(path: str) -> ProcessDefinition | None: