From 32b2f6ea9950420f8a37f6c89639f8f04fa84f10 Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Fri, 26 Jan 2024 15:27:49 +0900 Subject: [PATCH] Automatically check if juliacall was already imported --- pysr/julia_helpers.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pysr/julia_helpers.py b/pysr/julia_helpers.py index 02c92f2ba..423a5138b 100644 --- a/pysr/julia_helpers.py +++ b/pysr/julia_helpers.py @@ -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( @@ -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