@@ -226,33 +226,32 @@ def exec(self, code, /):
226226 if excinfo is not None :
227227 raise ExecutionFailed (excinfo )
228228
229- def call (self , callable , / ):
230- """Call the object in the interpreter with given args/kwargs.
229+ def _call (self , callable , args , kwargs ):
230+ res , excinfo = _interpreters .call (self ._id , callable , args , kwargs , restrict = True )
231+ if excinfo is not None :
232+ raise ExecutionFailed (excinfo )
233+ return res
231234
232- Only functions that take no arguments and have no closure
233- are supported .
235+ def call ( self , callable , / , * args , ** kwargs ):
236+ """Call the object in the interpreter with given args/kwargs .
234237
235- The return value is discarded.
238+ Nearly all callables, args, kwargs, and return values are
239+ supported. All "shareable" objects are supported, as are
240+ "stateless" functions (meaning non-closures that do not use
241+ any globals). This method will fall back to pickle.
236242
237243 If the callable raises an exception then the error display
238- (including full traceback) is send back between the interpreters
244+ (including full traceback) is sent back between the interpreters
239245 and an ExecutionFailed exception is raised, much like what
240246 happens with Interpreter.exec().
241247 """
242- # XXX Support args and kwargs.
243- # XXX Support arbitrary callables.
244- # XXX Support returning the return value (e.g. via pickle).
245- excinfo = _interpreters .call (self ._id , callable , restrict = True )
246- if excinfo is not None :
247- raise ExecutionFailed (excinfo )
248+ return self ._call (callable , args , kwargs )
248249
249- def call_in_thread (self , callable , / ):
250+ def call_in_thread (self , callable , / , * args , ** kwargs ):
250251 """Return a new thread that calls the object in the interpreter.
251252
252253 The return value and any raised exception are discarded.
253254 """
254- def task ():
255- self .call (callable )
256- t = threading .Thread (target = task )
255+ t = threading .Thread (target = self ._call , args = (callable , args , kwargs ))
257256 t .start ()
258257 return t
0 commit comments