From 43f9f5114573ce03da449a05aa960b3af73daf62 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Wed, 24 Jul 2024 10:48:16 +0200 Subject: [PATCH] 'remove_tray_server_url' has force option --- client/ayon_core/tools/tray/lib.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/client/ayon_core/tools/tray/lib.py b/client/ayon_core/tools/tray/lib.py index 7462c5d7c6..555937579f 100644 --- a/client/ayon_core/tools/tray/lib.py +++ b/client/ayon_core/tools/tray/lib.py @@ -191,19 +191,26 @@ def set_tray_server_url(tray_url: Optional[str], started: bool): json.dump(data, stream) -def remove_tray_server_url(): +def remove_tray_server_url(force: Optional[bool] = False): """Remove tray information file. Called from tray logic, do not use on your own. + + Args: + force (Optional[bool]): Force remove tray information file. + """ filepath = _get_tray_info_filepath() if not os.path.exists(filepath): return - with open(filepath, "r") as stream: - data = json.load(stream) + try: + with open(filepath, "r") as stream: + data = json.load(stream) + except BaseException: + data = {} - if data.get("pid") == os.getpid(): + if force or not data or data.get("pid") == os.getpid(): os.remove(filepath) @@ -250,7 +257,7 @@ def get_tray_state( info = _get_tray_information(tray_url) if not info: # Remove the information as the tray is not running - remove_tray_server_url() + remove_tray_server_url(force=True) return TrayState.NOT_RUNNING return TrayState.RUNNING @@ -296,7 +303,7 @@ def main(): pid = file_info.get("pid") if pid is not None: os.kill(pid, signal.SIGTERM) - remove_tray_server_url() + remove_tray_server_url(force=True) # Prepare the file with 'pid' information as soon as possible try: