Skip to content

Commit 12a5041

Browse files
authored
Merge pull request #147 from davide84/master
FIX: issue #146 (No output in Matlab 2020b)
2 parents ab41f9b + 0ee1bfd commit 12a5041

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

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, 'async': 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)