Skip to content

Commit

Permalink
Automatically check if juliacall was already imported
Browse files Browse the repository at this point in the history
  • Loading branch information
MilesCranmer committed Jan 26, 2024
1 parent 2abf017 commit 32b2f6e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pysr/julia_helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
"""Functions for initializing the Julia environment and installing deps."""
import os
import sys
import warnings

if "juliacall" in sys.modules:
warnings.warn(
"juliacall module already imported. Make sure that you have set `PYTHON_JULIACALL_HANDLE_SIGNALS=yes` to avoid segfaults."
)

# Required to avoid segfaults (https://juliapy.github.io/PythonCall.jl/dev/faq/)
if os.environ.get("PYTHON_JULIACALL_HANDLE_SIGNALS", "yes") != "yes":
warnings.warn(
Expand All @@ -10,7 +16,7 @@
)

os.environ["PYTHON_JULIACALL_HANDLE_SIGNALS"] = "yes"
os.environ["JULIA_NUM_THREADS"] = "auto"
os.environ["JULIA_NUM_THREADS"] = os.environ.get("JULIA_NUM_THREADS", "auto")

import juliapkg
from juliacall import Main as jl
Expand Down

0 comments on commit 32b2f6e

Please sign in to comment.