Python GUI doesn't close after closing MATLAB
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello Team
I am opening my python pyside6 GUI from MATLAB 2023b using pyrunfile command.
I have observed that if I close my MATLAB first, my python GUI still remains open for a very long time and I have to go to the task manager to end the task. Why is it so?
How does MATLAB handle the closing of applications?
1 Kommentar
Antworten (1)
aditi bagora
am 4 Mär. 2025
Hi Rajiv,
As @dpb pointed out when you use the pyrunfile command in MATLAB to execute a Python script, it runs the script in "Out of Process" mode. This means that MATLAB launches the Python interpreter as a separate process, which is independent of the MATLAB session. As a result, closing MATLAB does not automatically terminate the Python process. This behavior can be confirmed by running the pyenv command in MATLAB, which will show you the current execution mode.
In order to fix the issue, the best possible solution is to handle closing of the application in the script itself. However, You can change the execution mode to "In Process" using the pyenv command, but this might lead to compatibility issues with certain third-party Python libraries.
Please refer to the following MathWorks documentation links for detailed information on pyrunfile and pyenv.
2 Kommentare
dpb
am 28 Mär. 2025
Have you terminated pyenv and then restarted MATLAB in "InProcess" mode after? I note the state is maintained between sessions of MATLAB so if you used something else in between it could have been reset.
Use the taskmanger to monitor, but it's still possible the python environment launches its own thread/task for the gui. In the end, it's going to be the OS and internal behavior of Python that is controlling here, not MATLAB and "it is what it is"; there is no "fix" in MATLAB.
Siehe auch
Kategorien
Mehr zu Call Python from MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!