Skip to content

Commit 0ee1bfd

Browse files
author
Davide Cester
committed
FIX: issue #146, back-comp for Matlab <= R2017a
1 parent be8ac96 commit 0ee1bfd

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

matlab_kernel/kernel.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ def _matlab(self):
8383
self.__matlab = matlab.engine.start_matlab()
8484
except matlab.engine.EngineError:
8585
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}
8694
self._validated_plot_settings = {
8795
"backend": "inline",
8896
"size": (560, 420),
@@ -253,8 +261,7 @@ def _execute_async(self, code):
253261
try:
254262
with pipes(stdout=_PseudoStream(partial(self.Print, end="")),
255263
stderr=_PseudoStream(partial(self.Error, end=""))):
256-
kwargs = { 'nargout': 0, 'background': True }
257-
future = self._matlab.eval(code, **kwargs)
264+
future = self._matlab.eval(code, **self._async_kwargs)
258265
future.result()
259266
except (SyntaxError, MatlabExecutionError, KeyboardInterrupt) as exc:
260267
pass

0 commit comments

Comments
 (0)