Signal problem

Discussion in 'Python' started by Fabio Durieux Lopes, Mar 27, 2008.

  1. Hello again! Full of problems today!

    This one is about signal treatment. I made a daemon and set it to
    treat 2 signals: SIGALRM and SIGTERM.

    It goes like this:
    signal.signal(signal.SIGTERM, daemon.signalHandler)
    signal.signal(signal.SIGALRM, aFilter.alarmHandler)


    On daemon.py I have:
    "
    ....
    terminate = False

    def signalHandler(signum, frame):
    terminate = True

    ....
    "

    And my main loop goes like this:

    'while(not daemon.terminate):'

    When the signal treatment was in the same file as my loop it
    worked just fine, and since I've separated it in another file it
    stopped working. The SIGALRM treatment, which remains in the same
    file, is still working. Any reason why it doesn't treat SIGTERM
    anymore? Does it have anything to do with the fact that 'terminate'
    is not a class variable? Any ideas?

    Thanks in advance!
     
    Fabio Durieux Lopes, Mar 27, 2008
    #1
    1. Advertising

  2. Fabio Durieux Lopes wrote:


    > def signalHandler(signum, frame):
    > terminate = True


    This creates a new variable named "terminate" inside the signalHandler
    function's local scope. To adjust the value of a module-level global from
    inside a function, use the "global" keyword:


    def signalHandler(signum, frame):
    global terminate
    terminate = True


    Jeffrey
     
    Jeffrey Froman, Mar 27, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael Pronath
    Replies:
    1
    Views:
    1,236
    Diez B. Roggisch
    Jan 3, 2005
  2. Jack Orenstein

    threading.Thread vs. signal.signal

    Jack Orenstein, Sep 18, 2005, in forum: Python
    Replies:
    0
    Views:
    497
    Jack Orenstein
    Sep 18, 2005
  3. Weng Tianxiang
    Replies:
    2
    Views:
    688
    Jonathan Bromley
    Jan 30, 2007
  4. Nicolas Moreau
    Replies:
    9
    Views:
    3,353
  5. dibacco73
    Replies:
    1
    Views:
    695
    joris
    Feb 12, 2009
Loading...

Share This Page