When using Matlab engine from Python, process [matlab_helper] <defunct> is left as zombie process

10 次查看(过去 30 天)
0.0 0.0 0 0 ? Zs 10:16 0:00 [matlab_helper] <defunct>
When I look at processes after using eng.quit() in Python, those are left behind.
I am using release 2022b.
  1 个评论
Venkat Siddarth Reddy
Hi Jani,
This situtation usually occurs if the MATLAB process is terminated unexpectedly or if its not properly closed by the python script.
A defunct process is one that has completed execution but still has an entry in the process table.This is usually sporadic in nature.
Can you please confirm whether this issue is repeating, even in the new session of python?

请先登录,再进行评论。

回答(1 个)

Varun
Varun 2024-1-22
Hi Jani,
Looks like you are not able successfully terminate the MATLAB process while using MATLAB engine for Python.
Make sure there are no unhandled exceptions occurring before or after the eng.quit() call. If an exception occurs, the quit() method might not be reached, leaving the MATLAB process running. Please refer the following example which has additional try-except block ensuring any errors during the quit() call are caught and printed, helping to identify potential issues.
import matlab.engine
try:
eng = matlab.engine.start_matlab()
# Your MATLAB commands here
except Exception as e:
print(f"Error: {e}")
finally:
try:
eng.quit()
except Exception as e:
print(f"Error during quit(): {e}")
You can also try using “eng.exit()” instead of “eng.quit()”, and see if it resolves the issue.
Please refer the following documentation to learn more about “Start and Stop MATLAB Engine for Python”:

类别

Help CenterFile Exchange 中查找有关 Call MATLAB from Python 的更多信息

产品


版本

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by