I have a long loop in a C WSTP process, within which I intermittently check for abort messages sent by the front-end:
void checkIfUserAborted() {
if (WSMessageReady(stdlink)) {
int code, arg;
WSGetMessage(stdlink, &code, &arg);
if (code == WSTerminateMessage || code == WSInterruptMessage ||
code == WSAbortMessage || code == WSImDyingMessage) {
// throw error
}
}
}
void myWSTPFunc() {
try {
for (big loop) {
checkIfUserAborted();
// do task
}
} catch ... {
// handle abort
}
}
This code was adapted from this great but very outdated doc, which uses the defunct MLAbort (for which the replacement WSAbort somehow went missing). This code previously worked in version 11 of Mathematica on MacOS, allowing me to detect and handle the abort during myWSTPFunc(), as invoked by the user clicking Evaluation > Abort Evaluation in their notebook.
As of Mathematica v13 however, this process no longer works. Invoking Evaluation > Abort Evaluation no longer triggers a WSAbortMessage discoverable by checkIfUserAborted().
I managed to get LinkSnooper working as per this post, but all it logs during my abort invocation is
****** Message FE ---> K: on Main: 3
I hence have two questions:
- How can I use LinkSnooper to see the specific message my Abort induced?
- Is there an updated way to listen for aborts in WSTP? Is
LinkInterruptrelevant?
MLAbortdoes not work? – Szabolcs Jul 22 '22 at 07:16ML-named functions are not "defunct". They work fine, and should be completely equivalent to theWS-ones. If there is any difference whatsoever, it's a bug and you should report it to Wolfram. – Szabolcs Jul 22 '22 at 07:18MLAbortis undefined, andWSAbortis undeclared. It doesn't get more defunct than that. – Anti Earth Jul 26 '22 at 00:11MLAbortworks perfectly fine here. – Szabolcs Jul 26 '22 at 06:04#include "wstp.h"and making any reference to eitherMLAbortorWSAbort(causing an undefined compile error). I'm using the 2017 Linux/MacOSwstp.h, and the 2019 Windowswstp.h. What year are you using? – Anti Earth Jul 26 '22 at 06:36MLGetMessagedirectly vs using a message handler. I am curious what your application is given that you are writing your own main loop. – Szabolcs Jul 26 '22 at 07:09