Skip to content

Helpful Tools and Tips

Isaac Wilcove edited this page Jul 14, 2017 · 3 revisions

Python Ctrl+C Exit Handler

To exit out of a forever loop using ctrl+c

// Imports required
import sys
import signal

// Exit function
def ctrlc_exit(signal, frame):
    sys.exit(0)

// Run the listener
signal.signal(signal.SIGINT, ctrlc_exit)

// Forever loop goes here

C++ Ctrl+C Exit Handler

To exit out of a forever loop using ctrl+c

// Includes required
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

// Exit function
void ctrlc_exit(int signal){
    printf("Exiting from signal: %d", signal);
    exit(0);
}

// Main function
int main(int argc,char** argv)
{

    // Create handler
    struct sigaction handler;

    // Handler properties
    handler.sa_handler = ctrlc_exit;
    sigemptyset(&handler.sa_mask);
    handler.sa_flags = 0;

    // Run the listener
    sigaction(SIGINT, &handler, NULL);

    // Forever loop goes here

}

Formula1Epoch

The self-driving car trained with deep learning

Clone this wiki locally