From fd6b6b02ec73847d514815231b00e5a6fa9f1f7e Mon Sep 17 00:00:00 2001 From: Raphael <155643707+rw-bsi@users.noreply.github.com> Date: Sat, 9 Nov 2024 16:18:54 +0000 Subject: [PATCH] Update tasks.py Catches segfaults invoking ifcopenshell.open() --- backend/apps/ifc_validation/tasks.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/backend/apps/ifc_validation/tasks.py b/backend/apps/ifc_validation/tasks.py index 81f64e0..d5904ff 100644 --- a/backend/apps/ifc_validation/tasks.py +++ b/backend/apps/ifc_validation/tasks.py @@ -330,6 +330,17 @@ def parse_info_subtask(self, prev_result, id, file_name, *args, **kwargs): task.mark_as_initiated() + # try to open IFC file (catch segfaults) + try: + code = "import ifcopenshell; ifcopenshell.open('" + file_path + "')" + check_program = [sys.executable, '-c', code, file_path] + logger.debug(f'Command for {self.__qualname__}: {" ".join(check_program)}') + subprocess.run(check_program, check=True) + + except subprocess.CalledProcessError as err: + task.mark_as_failed(err) + raise + # retrieve IFC info try: task.set_process_details(None, f"(module) ifcopenshell.open() for file '{file_path}')")