@@ -109,11 +109,16 @@ def int_option(name, *, accept_auto=False, **kw):
109
109
raise ValueError (f'{ s } : expecting an int' + (' or auto' if accept_auto else "" ))
110
110
111
111
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 ]
117
122
118
123
argc = len (argv )
119
124
argc = c .c_int (argc )
@@ -138,7 +143,7 @@ def args_from_config():
138
143
CONFIG ['opt_sysimage' ] = sysimg = path_option ('sysimage' , check_exists = True )[0 ]
139
144
CONFIG ['opt_threads' ] = int_option ('threads' , accept_auto = True )[0 ]
140
145
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 ]
142
147
CONFIG ['opt_startup_file' ] = choice ('startup_file' , ['yes' , 'no' ])[0 ]
143
148
144
149
# Stop if we already initialised
@@ -225,6 +230,24 @@ def jlstr(x):
225
230
226
231
CONFIG ['inited' ] = True
227
232
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
+
228
251
init ()
229
252
230
253
def load_ipython_extension (ip ):
0 commit comments