Command for unsharing Matlab Session

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
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.
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?
Hi Till,
Yes, it is not possible to stop sharing from the opened MATLAB without closing the MATLAB session.
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

Community Treasure Hunt

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

Start Hunting!

Translated by