-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure julia is loaded as soon as possible
- Loading branch information
1 parent
7aa7884
commit caf58a4
Showing
4 changed files
with
42 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
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( | ||
"PYTHON_JULIACALL_HANDLE_SIGNALS environment variable is set to something other than 'yes' or ''. " | ||
+ "You will experience segfaults if running with multithreading." | ||
) | ||
|
||
if os.environ.get("JULIA_NUM_THREADS", "auto") != "auto": | ||
warnings.warn( | ||
"JULIA_NUM_THREADS environment variable is set to something other than 'auto', " | ||
"so PySR was not able to set it. You may wish to set it to `'auto'` for full use " | ||
"of your CPU." | ||
) | ||
|
||
# TODO: Remove these when juliapkg lets you specify this | ||
for k, default in ( | ||
("PYTHON_JULIACALL_HANDLE_SIGNALS", "yes"), | ||
("JULIA_NUM_THREADS", "auto"), | ||
("JULIA_OPTIMIZE", "3"), | ||
): | ||
os.environ[k] = os.environ.get(k, default) | ||
|
||
from juliacall import Main as jl # type: ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters