Python GUI doesn't close after closing MATLAB
조회 수: 8 (최근 30일)
이전 댓글 표시
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
답변 (1개)
aditi bagora
2025년 3월 4일
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
dpb
2025년 3월 28일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!