I want to monitor this python process from openframeworks using c++ watchdog

Hi, All.

I have executed python process like this -
$ python3 infer.py

And, I want to monitor this python process from openframeworks using c++ watchdog.
When this python process killed, It must be restarted by c++ watchdog.

Is there any watchdog addons for OF which can monitor python?
How can I get this ?

Thanks in advance.
Best,
@bemoregt.

Can you just use some kind of heartbeat in the apps, maybe a udp signal every 10 seconds, where the c++ app sends a message and waits for a reply from the python script. If there is no reply for 15 seconds then run a command to start the python script again.

1 Like

Hi, @fresla.

Is there any example code for that.

Thanks.

I have made a few kind of systems like that, It is pretty simple, just send a message and start a timer when you do that. If you receive the response reset the timer. If the timer goes over the limit run the script.

Here is some scraps of code from a project so they wont work as is but can be a good start:

    uint64_t rpiAckSendTimer, rpiAckReceiveTimer;
    ofxOscSender rpiOscSender;
    ofxOscReceiver oscReceive;
    ofxOscMessage ackMessage;

void ofApp::setupOSC(){
    oscReceive.setup(antimanOSCReceivePort);
    rpiOscSender.setup(rpiIPAddress, rpiOSCReceivePort);
    ackMessage.setAddress("/ack");
}
void ofApp::setupRPIStatus(){
    rpiAckSendTimer =  ofGetElapsedTimeMillis();
    rpiAckReceiveTimer =  ofGetElapsedTimeMillis();
    rpiOscSender.sendMessage(ackMessage);
    ofLogNotice("Antiman::OSC to mask") << "Sent osc ack to RPI";
}

in update:

  if (ofGetElapsedTimeMillis() - rpiAckReceiveTimer > 4500) {
        rpiOscSender.sendMessage(ackMessage);
        ofLogNotice("Antiman::OSC to mask") << "Sent osc ack to RPI";
        rpiAckSendTimer = ofGetElapsedTimeMillis();
    }
    
    if (ofGetElapsedTimeMillis() - rpiAckSendTimer > 15000) {
        ofLogNotice("Antiman::OSC to mask") << "RPI not responding to Ack messages";
// here is the fail point so you would restart your script here.
    }

   while( oscReceive.hasWaitingMessages() ){
        ofxOscMessage m;
        oscReceive.getNextMessage(m);
        
        if( m.getAddress() == "/ack" && m.getRemoteHost() == rpiIPAddress){
            rpiAckReceiveTimer = ofGetElapsedTimeMillis();
            incomingRPIStatus.isConnected = true;
            ofLogNotice("Antiman::OSC to mask") << "Received osc ack from RPI";
            
        }
}

This system uses two timers as that way I wait before sending a message so there is a little less chatter on the network.

1 Like

@fresla

Many Thanks.

It’s very helpfull to me.

I’ll try this.