Coder Social home page Coder Social logo

Comments (4)

SgtBurned avatar SgtBurned commented on July 29, 2024

Code? It could be that Ctrl+C is quitting because it has nothing else to run? Post your code and I will review it. Might be a similar problem to mine ( os.kill(PID, signal.SIGINT) will kill PWM aswell and shut main program down ).

from rpio.

tuomas2 avatar tuomas2 commented on July 29, 2024

I must produce separate example case for this. The problem occurs in a slightly larger code that is not open (yet). Practically there are other threads running and in main thread i have this try KeyboardException that should handle ctrl+c cleanly (and will shut down other threads cleanly as well). If this is not enough, I try to figure out simple an small code for you next weekend.

from rpio.

mlv avatar mlv commented on July 29, 2024

This is caused by source/c_pwm/pwm.c trapping all signals:

// Catch all signals possible - it is vital we kill the DMA engine
// on process exit!
static void
setup_sighandlers(void)
{
    int i;
    for (i = 0; i < 64; i++) {
        struct sigaction sa;
        memset(&sa, 0, sizeof(sa));
        sa.sa_handler = (void *) terminate;
        sigaction(i, &sa, NULL);
    }
}

I won't argue the importance of shutting down the DMA engine, but I'd like to think there's a better way of handling it (maybe be a little more discriminating? Only trap signals that would normally be fatal that don't already have handlers?).

This bit me in a different way. I have a server that's just quietly running in a tmux window. That is, until I change it's window size. A window size change sends a SIGWINCH to the process. It would normally be ignored (what care I for window sizes?), but setup_sighandlers() thinks the sky is falling when the window size changes and shuts down my server.

@tuomas2 what you can do is save the SIGINT handler and restore it afterwards. For example:

import signal
saveintsig=signal.getsignal(signal.SIGINT)

# then do the PWM setup
...
# after PWM has been setup...

signal.signal(signal.SIGINT, saveintsig)
try:
    doyourstuff()
except KeyboardInterrupt:
    sys.exit(0)

from rpio.

mkj avatar mkj commented on July 29, 2024

I think setup_sighandlers should only handle signals 1-32. 33 onwards are realtime signals. The following whitelist are safe to ignore, they don't terminate the process or are handled by Python

SIGCHLD
SIGCONT
SIGTSTP
SIGTTIN
SIGTTOU
SIGURG
SIGWINCH
SIGPIPE (by Python)
SIGINT (by Python)
SIGIO

from rpio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.