Skip to content

Commit 5f58a97

Browse files
author
Christopher Doris
committed
initialises using Base._start()
1 parent 567c01b commit 5f58a97

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

pysrc/juliacall/__init__.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,14 @@ def path_option(name, default=None):
127127
os.environ['JULIA_PYTHONCALL_LIBPTR'] = str(c.pythonapi._handle)
128128
os.environ['JULIA_PYTHONCALL_EXE'] = sys.executable or ''
129129
os.environ['JULIA_PYTHONCALL_PROJECT'] = project
130+
os.environ['JULIA_PYTHONCALL_INIT_JL'] = os.path.join(os.path.dirname(__file__), 'init.jl')
130131
script = '''
131-
try
132-
import Pkg
133-
Pkg.activate(ENV["JULIA_PYTHONCALL_PROJECT"], io=devnull)
134-
import PythonCall
135-
catch err
136-
print(stderr, "ERROR: ")
137-
showerror(stderr, err, catch_backtrace())
138-
flush(stderr)
139-
rethrow()
140-
end
141-
'''
132+
# This uses some internals, but Base._start() gets the state more like Julia
133+
# is if you call the executable directly, in particular it creates workers when
134+
# the --procs argument is given.
135+
push!(Core.ARGS, ENV["JULIA_PYTHONCALL_INIT_JL"])
136+
Base._start()
137+
'''
142138
res = lib.jl_eval_string(script.encode('utf8'))
143139
if res is None:
144140
raise Exception('PythonCall.jl did not start properly')

pysrc/juliacall/init.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
try
2+
import Pkg
3+
Pkg.activate(ENV["JULIA_PYTHONCALL_PROJECT"], io=devnull)
4+
import PythonCall
5+
catch err
6+
print(stderr, "ERROR: ")
7+
showerror(stderr, err, catch_backtrace())
8+
flush(stderr)
9+
rethrow()
10+
end

0 commit comments

Comments
 (0)