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 日

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 件のコメント

Till Temmen
Till Temmen 2022 年 10 月 11 日
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?
Gowthami
Gowthami 2022 年 10 月 11 日
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 件)

カテゴリ

製品

リリース

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