@@ -83,6 +83,14 @@ def _matlab(self):
83
83
self .__matlab = matlab .engine .start_matlab ()
84
84
except matlab .engine .EngineError :
85
85
self .__matlab = matlab .engine .connect_matlab ()
86
+ # detecting the correct kwargs for async running
87
+ # matlab 'async' param is deprecated since it became a keyword in python 3.7
88
+ # instead, 'background' param is available and recommended since Matlab R2017b
89
+ self ._async_kwargs = {'nargout' : 0 , 'async' : True }
90
+ try :
91
+ self ._matlab .eval ('version' , ** self ._async_kwargs )
92
+ except SyntaxError :
93
+ self ._async_kwargs = {'nargout' : 0 , 'background' : True }
86
94
self ._validated_plot_settings = {
87
95
"backend" : "inline" ,
88
96
"size" : (560 , 420 ),
@@ -253,8 +261,7 @@ def _execute_async(self, code):
253
261
try :
254
262
with pipes (stdout = _PseudoStream (partial (self .Print , end = "" )),
255
263
stderr = _PseudoStream (partial (self .Error , end = "" ))):
256
- kwargs = { 'nargout' : 0 , 'async' : True }
257
- future = self ._matlab .eval (code , ** kwargs )
264
+ future = self ._matlab .eval (code , ** self ._async_kwargs )
258
265
future .result ()
259
266
except (SyntaxError , MatlabExecutionError , KeyboardInterrupt ) as exc :
260
267
pass
0 commit comments