Programmatically interrupt MATLAB on Windows
11 ビュー (過去 30 日間)
古いコメントを表示
When using MATLAB through the GUI, I can easily interrupt a computation by pressing Ctrl-C.
On Unix systems there is a solution: send a SIGINT signal. This will not kill MATLAB. It'll only interrupt the computation (i.e. exactly what I want). I am looking for a solution that works on Windows.
Use case: this is for a Mathematica-MATLAB interface. I want to be able to forward interrupts from Mathematica to MATLAB. The functionality is working and implemented on Linux/OSX, but I'd prefer to have it for the majority Windows platform as well.
EDIT: I'm also interested in solution that work with the MEX interface. The MEX function would be multi-threaded where the first thread is running an evalc(), and the second is watching for interrupt conditions. How would the second thread interrupt the evalc()? I have less hope for this with MEX than with Engine though.
UPDATE: I still haven't found any way to do this with the Engine interface, but I did find something which might work with MEX. The libut library has a function called utSetInterruptPending(). When running sequentially, utSetInterruptPending(1) will interrupt MATLAB (as tested with calllib()). Does anyone know utSetInterruptPending() is safe to call in a MEX function from a different thread than the main one?
7 件のコメント
Iain
2013 年 5 月 21 日
I mean if you, in your matlab code, check to see if something has been done, say, a file being written to a known location, and if so, have the matlab code either stop execution, or, say, execute the code in that file.
回答 (3 件)
Walter Roberson
2013 年 5 月 20 日
MS Windows XP SP2 and later support POSIX signals including (presumably) SIG_INT.
2 件のコメント
Walter Roberson
2020 年 3 月 27 日
編集済み: Walter Roberson
2020 年 6 月 8 日
It looks like the various tools available to send a signal to an id, do so by sending a WM_CLOSE or WM_TERMINATE message. Unfortunately MATLAB would not be able to tell those apart from user request to terminate the program.
I find evidence that console applications can bind in handlers for control-break, but matlab is not generally a console application and I do not know if it does that binding (and I have not seen yet how a different process can provoke it)
Jan
2013 年 5 月 21 日
I assume, you do not want to stop the engine temporarily, like Ctrl-C in the application, but kill the job. Then the windows command taskkill will help.
3 件のコメント
Jan
2013 年 5 月 22 日
What do you expect as internal state of an interrupted engine? When Matlab is not run as application with a GUI, I cannot imagine, what interrupting without killing can be useful for. Do you want to resume later one?
Nilson Martinez-Lopez
2020 年 3 月 27 日
I have an example where I'd like to do this. I am running DAQ toolbox audio data input using startBackground(session). This is run from a callback function followed by wait(session). MATLAB is Busy, unless I use CTRL-C to stop it. I'd like to map a button from the UI to stop it in the same manner.
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!