@@ -109,11 +109,16 @@ def int_option(name, *, accept_auto=False, **kw):
109109 raise ValueError (f'{ s } : expecting an int' + (' or auto' if accept_auto else "" ))
110110
111111 def args_from_config ():
112- argv = ["--" + opt [4 :].replace ("_" , "-" )+ "=" + val for opt , val in CONFIG .items ()
113- if val is not None and opt .startswith ("opt_" )]
114- argv = [CONFIG ['exepath' ]]+ argv
115- if sys .version_info [0 ] >= 3 :
116- argv = [s .encode ("utf-8" ) for s in argv ]
112+ argv = [CONFIG ['exepath' ]]
113+ for opt , val in CONFIG .items ():
114+ if opt .startswith ('opt_' ):
115+ if val is None :
116+ if opt == 'opt_handle_signals' :
117+ val = 'no'
118+ else :
119+ continue
120+ argv .append ('--' + opt [4 :].replace ('_' , '-' ) + '=' + val )
121+ argv = [s .encode ("utf-8" ) for s in argv ]
117122
118123 argc = len (argv )
119124 argc = c .c_int (argc )
@@ -138,7 +143,7 @@ def args_from_config():
138143 CONFIG ['opt_sysimage' ] = sysimg = path_option ('sysimage' , check_exists = True )[0 ]
139144 CONFIG ['opt_threads' ] = int_option ('threads' , accept_auto = True )[0 ]
140145 CONFIG ['opt_warn_overwrite' ] = choice ('warn_overwrite' , ['yes' , 'no' ])[0 ]
141- CONFIG ['opt_handle_signals' ] = choice ('handle_signals' , ['yes' , 'no' ], default = 'no' )[0 ]
146+ CONFIG ['opt_handle_signals' ] = choice ('handle_signals' , ['yes' , 'no' ])[0 ]
142147 CONFIG ['opt_startup_file' ] = choice ('startup_file' , ['yes' , 'no' ])[0 ]
143148
144149 # Stop if we already initialised
@@ -225,6 +230,24 @@ def jlstr(x):
225230
226231 CONFIG ['inited' ] = True
227232
233+ if CONFIG ['opt_handle_signals' ] is None :
234+ if Base .Threads .nthreads () > 1 :
235+ # a warning to help multithreaded users
236+ # TODO: should we set PYTHON_JULIACALL_HANDLE_SIGNALS=yes whenever PYTHON_JULIACALL_THREADS != 1?
237+ warnings .warn (
238+ "Julia was started with multiple threads "
239+ "but multithreading support is experimental in JuliaCall. "
240+ "It is recommended to restart Python with the environment variable "
241+ "PYTHON_JULIACALL_HANDLE_SIGNALS=yes "
242+ "set, otherwise you may experience segfaults or other crashes. "
243+ "Note however that this interferes with Python's own signal handling, "
244+ "so for example Ctrl-C will not raise KeyboardInterrupt. "
245+ "See https://juliapy.github.io/PythonCall.jl/stable/faq/#Is-PythonCall/JuliaCall-thread-safe? "
246+ "for further information. "
247+ "You can suppress this warning by setting "
248+ "PYTHON_JULIACALL_HANDLE_SIGNALS=no."
249+ )
250+
228251init ()
229252
230253def load_ipython_extension (ip ):
0 commit comments