Clear Filters
Clear Filters

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

24 views (last 30 days)
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 Comment
Venkat Siddarth Reddy
Venkat Siddarth Reddy on 16 Jan 2024
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?

Sign in to comment.

Answers (1)

Varun
Varun on 22 Jan 2024
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”:

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!