Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When I use 'transplant.Matlab()' to start up Matlab session , how could I use python code to clase the Matlab session?Now I need to close the window manually. Thanks so much! #91

Open
chaohcc opened this issue Jan 15, 2021 · 15 comments

Comments

@chaohcc
Copy link

chaohcc commented Jan 15, 2021

No description provided.

@chaohcc chaohcc changed the title When I use 'transplant.Matlab()' to start up Matlab session , how could I use python code to clase the Matlab session When I use 'transplant.Matlab()' to start up Matlab session , how could I use python code to clase the Matlab session?Now I need to close the window manually. Thanks so much! Jan 15, 2021
@chaohcc
Copy link
Author

chaohcc commented Jan 15, 2021

I use python code: matlab.close(); matlab.exit(); matlab.send_message('die'), it seems does't work.
Thank so much!

@bastibe
Copy link
Owner

bastibe commented Jan 15, 2021

Can you describe your problem in a bit more detail and provide some example code so we can reproduce it?

@chaohcc
Copy link
Author

chaohcc commented Jan 16, 2021

Can you describe your problem in a bit more detail and provide some example code so we can reproduce it?

Thank you!
import transplant
matlab = transplant.Matlab()
res = matlab.Myfun(data,para)
Y = res[0]
A= res[1]
the code above is run correct,and start a matlab session, and run my matlab function "Myfun(data,para)", and return the result of matlab to python.
My question is how should I use code or command in python to close the matlab session?
Now the matlab session can't close itself, I need close it's window manually, and if the matlab session didn't close, the python code after the matlab session will not run. In other words, the code,
Y = res[0]
A= res[1]
would run after I close the matlab session manually.
Sorry, my English is poor, hope I have made it clearly, thank you!

@bastibe
Copy link
Owner

bastibe commented Jan 20, 2021

If I understand you correctly, your Myfun does not return? That would be a problem in Myfun, not Transplant.

However, you say "I need to close its window manually", which implies that you are doing graphical things inside Myfun. This can be tricky within Transplant, as Transplant does not / can not drawnow every so often, which some Matlab code requires. You can try adding a few drawnow() to your Myfun and see if that helps.

@chaohcc
Copy link
Author

chaohcc commented Jan 22, 2021

If I understand you correctly, your Myfun does not return? That would be a problem in Myfun, not Transplant.

However, you say "I need to close its window manually", which implies that you are doing graphical things inside Myfun. This can be tricky within Transplant, as Transplant does not / can not drawnow every so often, which some Matlab code requires. You can try adding a few drawnow() to your Myfun and see if that helps.

Thank you! my problem is my python code start matlab successfuly and open a matlab window, run Myfun correctly. but python code not continus until the matlab window closed . seems the matlab.exit() methed is not working.

@bastibe
Copy link
Owner

bastibe commented Jan 27, 2021

What sort of Matlab window is being opened? Like a figure? What operating system are you running?

@chaohcc
Copy link
Author

chaohcc commented Feb 1, 2021

What sort of Matlab window is being opened? Like a figure? What operating system are you running?
Thank you!
here is the code I start matlab
image

I run on Windows10. The opened Matlab window is like the following picture:
image

Best wishes! Thank you!

@bastibe
Copy link
Owner

bastibe commented Feb 3, 2021

Is that Window interactive, i.e. can you type something in there and get a response? That shouldn't happen.

Could you debug into your transplant_master.py, and report back the value of process_arguments in line 568?

@chaohcc
Copy link
Author

chaohcc commented Feb 10, 2021

Is that Window interactive, i.e. can you type something in there and get a response? That shouldn't happen.

Could you debug into your transplant_master.py, and report back the value of process_arguments in line 568?

Thank you! Yes, I can type something in window and it will run and give a response. I debug transplant_master.py, the value of process_arguments :
image
Thank you!

@bastibe
Copy link
Owner

bastibe commented Feb 10, 2021

If there is a window, it should not be interactive. If it is interactive, transplant must have crashed. It's a sad fact of Matlab that some errors can't be caught. Do you see any error messages that might indicate a crash of transplant_remote?

@chaohcc
Copy link
Author

chaohcc commented Feb 16, 2021

If there is a window, it should not be interactive. If it is interactive, transplant must have crashed. It's a sad fact of Matlab that some errors can't be caught. Do you see any error messages that might indicate a crash of transplant_remote?
Thank you! I haven't see any error messages that might indicate a crash of transplant_remote. Is there any way to see it or debug?

@bastibe
Copy link
Owner

bastibe commented Feb 17, 2021

The errors should show up either in your Python console, or in Matlab's window. Although since you seem to be running inside an IDE, perhaps the IDE is eating STDERR?

Perhaps you will see an error if you try running your program in a plain terminal instead of an IDE.

@chaohcc
Copy link
Author

chaohcc commented Feb 19, 2021

The errors should show up either in your Python console, or in Matlab's window. Although since you seem to be running inside an IDE, perhaps the IDE is eating STDERR?

Perhaps you will see an error if you try running your program in a plain terminal instead of an IDE.
okey, thank you so much, I will have a try running my program in a plain terminal.

@alien19
Copy link

alien19 commented Jan 23, 2023

Hello,
I have the same issue here -I use the transplant module on windows to call Matlab functions in Python but can't get rid of the command window that pop up neither exit the Matlab session-, has anyone found a solution.

edit:
eng.quit() does close the command window but raises "RuntimeError: Process died unexpectedly"
eng.close() returns 1 but doesn't do anything
eng.exit() requires me to write in the matlab command ">> exit()" too to close the session

Thanks in advance.

@bastibe
Copy link
Owner

bastibe commented Jan 23, 2023

It may be that matlab on Windows behaves differently from matlab on unices. Try inserting exit() into https://github.com/bastibe/transplant/blob/master/transplant/transplant_remote.m#L37 and see if that helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants