Signal problem

  • Thread starter Fabio Durieux Lopes
  • Start date
F

Fabio Durieux Lopes

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!
 
J

Jeffrey Froman

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top