Hello,
i'm using the Matlab Shared Session to connect Matlab to Python. The command i am using is
matlab.engine.shareEngine("matlab1");
Is there a possibility to unshare the session with a matlab command? At the moment i'm always restarting matlab to close the session, it would be great if there is a faster way.
Thank you very much for your help

 채택된 답변

Gowthami
Gowthami 2022년 10월 11일

0 개 추천

Hello,
It is my understanding that you want to stop the shared session of Matlab engine for Python.
If you exit Python with an engine still running, then Python automatically stops the engine and its MATLAB process.
I hope it helps.

댓글 수: 5

Hello,
thank you for your help.
I'm sharing my session in Matlab with
matlab.engine.shareEngine("matlab1");
and then i connect from Python with the commands
import matlab.engine
eng = matlab.engine.connect_matlab("matlab1")
I just tested if the shared session stops if i end the Python execution (with and without the command eng.quit()). Whenever i call matlab.engine.shareEngine("matlab1"); a second time it tells me "The current MATLAB session is shared already. To share a session with a different name, launch a new MATLAB session, and then specify the name when you share it."
What is the equivalent of eng.quit() (which seems to be for Python) for Matlab? Or is there a way to just "unshare" the shared session with a Matlab command?
Hi,
Yes, when a session already in running and If you run the commad,
matlab.engine.shareEngine("matlab1");
You may get the error as "The current MATLAB session is shared already. To share a session with a different name, launch a new MATLAB session, and then specify the name when you share it."
In Python , you may start multiple MATLAB engines using the command,
matlab.engine.start_matlab
Or launch multiple shared MATLAB sessions and connect to them using the command,
matlab.engine.connect_matlab
to run multiple functions simultaneously.
The only way to unshare the session is to exit Python with an engine still running or call either the exit or the quit function.
I hope this helps.
Till Temmen
Till Temmen 2022년 10월 11일
So, i can only stop a shared session if i started it with Python. If i started it from Matlab it is not possible to stop or unshare it without closing Matlab. Do i understand you right?
Gowthami
Gowthami 2022년 10월 12일
Hi Till,
Yes, it is not possible to stop sharing from the opened MATLAB without closing the MATLAB session.
Till Temmen
Till Temmen 2022년 10월 12일
Thank you very much for your help and clarifications. Would be great if something like that could be added :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

제품

릴리스

R2021a

질문:

2022년 10월 5일

댓글:

2022년 10월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by