From f37ffda96620745a418bd2ab5447dad89689f9ce Mon Sep 17 00:00:00 2001 From: Lincoln Stein Date: Sun, 24 Sep 2023 22:51:24 -0400 Subject: [PATCH] replace case statements with if/else to support python 3.9 --- .../session_processor_default.py | 35 +++++++++++-------- .../session_queue/session_queue_sqlite.py | 15 ++++---- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/invokeai/app/services/session_processor/session_processor_default.py b/invokeai/app/services/session_processor/session_processor_default.py index fbe754b897..d5d08cc779 100644 --- a/invokeai/app/services/session_processor/session_processor_default.py +++ b/invokeai/app/services/session_processor/session_processor_default.py @@ -47,20 +47,27 @@ class DefaultSessionProcessor(SessionProcessorBase): async def _on_queue_event(self, event: FastAPIEvent) -> None: event_name = event[1]["event"] - match event_name: - case "graph_execution_state_complete" | "invocation_error" | "session_retrieval_error" | "invocation_retrieval_error": - self.__queue_item = None - self._poll_now() - case "session_canceled" if self.__queue_item is not None and self.__queue_item.session_id == event[1][ - "data" - ]["graph_execution_state_id"]: - self.__queue_item = None - self._poll_now() - case "batch_enqueued": - self._poll_now() - case "queue_cleared": - self.__queue_item = None - self._poll_now() + # This was a match statement, but match is not supported on python 3.9 + if event_name in [ + "graph_execution_state_complete", + "invocation_error", + "session_retrieval_error", + "invocation_retrieval_error", + ]: + self.__queue_item = None + self._poll_now() + elif ( + event_name == "session_canceled" + and self.__queue_item is not None + and self.__queue_item.session_id == event[1]["data"]["graph_execution_state_id"] + ): + self.__queue_item = None + self._poll_now() + elif event_name == "batch_enqueued": + self._poll_now() + elif event_name == "queue_cleared": + self.__queue_item = None + self._poll_now() def resume(self) -> SessionProcessorStatus: if not self.__resume_event.is_set(): diff --git a/invokeai/app/services/session_queue/session_queue_sqlite.py b/invokeai/app/services/session_queue/session_queue_sqlite.py index 1cedf09c89..a13e13050e 100644 --- a/invokeai/app/services/session_queue/session_queue_sqlite.py +++ b/invokeai/app/services/session_queue/session_queue_sqlite.py @@ -59,13 +59,14 @@ class SqliteSessionQueue(SessionQueueBase): async def _on_session_event(self, event: FastAPIEvent) -> FastAPIEvent: event_name = event[1]["event"] - match event_name: - case "graph_execution_state_complete": - await self._handle_complete_event(event) - case "invocation_error" | "session_retrieval_error" | "invocation_retrieval_error": - await self._handle_error_event(event) - case "session_canceled": - await self._handle_cancel_event(event) + + # This was a match statement, but match is not supported on python 3.9 + if event_name == "graph_execution_state_complete": + await self._handle_complete_event(event) + elif event_name in ["invocation_error", "session_retrieval_error", "invocation_retrieval_error"]: + await self._handle_error_event(event) + elif event_name == "session_canceled": + await self._handle_cancel_event(event) return event async def _handle_complete_event(self, event: FastAPIEvent) -> None: