Skip to content

Commit c921d0c

Browse files
authored
Fix segfaulting in launcher's python code (#51)
1 parent 0be6141 commit c921d0c

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

launcher/app.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,9 @@ def file_upload(label: str, extensions: list[str], key: str,
707707
fmt = output_format or "MATPOWER"
708708
fmt_enum = _fmt_to_enum.get(fmt, f"exago.{fmt}")
709709
body.append(f"opf.save_solution({fmt_enum})")
710+
body.append("")
711+
body.append("# Delete opflow instance")
712+
body.append("del opf")
710713

711714
elif py_app == "SCOPFLOW":
712715
body += [
@@ -731,6 +734,9 @@ def file_upload(label: str, extensions: list[str], key: str,
731734
body.append("")
732735
body.append("# Print solution")
733736
body.append("scopf.print_solution(0)")
737+
body.append("")
738+
body.append("# Delete scopflow instance")
739+
body.append("del scopf")
734740

735741
elif py_app == "SOPFLOW":
736742
body += [
@@ -757,6 +763,9 @@ def file_upload(label: str, extensions: list[str], key: str,
757763
body.append("")
758764
body.append("# Print solution")
759765
body.append("sopf.print_solution(0)")
766+
body.append("")
767+
body.append("# Delete sopflow instance")
768+
body.append("del sopf")
760769

761770
elif py_app == "TCOPFLOW":
762771
body += [
@@ -780,6 +789,9 @@ def file_upload(label: str, extensions: list[str], key: str,
780789
body.append("")
781790
body.append("# Print solution")
782791
body.append("tcopf.print_solution(0)")
792+
body.append("")
793+
body.append("# Delete tcopflow instance")
794+
body.append("del tcopf")
783795

784796
elif py_app == "PFLOW":
785797
body += [
@@ -795,6 +807,9 @@ def file_upload(label: str, extensions: list[str], key: str,
795807
body.append("")
796808
body.append("# Print solution")
797809
body.append("pf.print_solution()")
810+
body.append("")
811+
body.append("# Delete pflow instance")
812+
body.append("del pf")
798813

799814
elif py_app == "DCOPFLOW":
800815
# DCOPFLOW has no Python bindings — skip init/finalize wrapper
@@ -809,11 +824,8 @@ def file_upload(label: str, extensions: list[str], key: str,
809824
lines += body
810825
lines += [
811826
"",
812-
"# Clean up",
813-
"try:",
814-
" exago.finalize()",
815-
"except Exception:",
816-
" pass # MPI finalization may throw during cleanup; results are valid",
827+
"# Close ExaGO",
828+
"exago.finalize()",
817829
]
818830

819831
python_code = "\n".join(lines)

0 commit comments

Comments
 (0)