python question for the list
Thu, 16 May 2013 05:18:46 -0700 Post Comments
Hi all,
i've got a rather puzzling python coding problem that I'm trying to solve
and I figured I'd ask the list for assistance.
If I have code that looks something like this:
import daemon
class bar():
def func():
print "Hello World!\n"
def sigusr1_handler(signum,frame):
foo.func()
def main():
foo = bar()
context = daemon.DaemonContext()
context.signal_map = {
signal.SIGUSR1: sigusr1_handler
}
with context:
if (__name__="__main__"):
main()
Basically, this code becomes a daemon process and defines a signal handler
for SIGUSR1 which calls a method from class bar as instantiated by foo.
Unfortunately, this doesn't work. When the signal handler gets called,
python throws a NameError and says that global name "foo" is not defined.
anybody know how I can get the python interpreter to recognize the foo
variable in the signal handler? I tried using __main__.foo.func() but that
didn't work either.
Any help appreciated.
Thanks,
Braun Brelin
--
Irish Linux Users' Group mailing list
About this list : http://mail.linux.ie/mailman/listinfo/ilug
Who we are : http://www.linux.ie/
Where we are : http://www.linux.ie/ map/
i've got a rather puzzling python coding problem that I'm trying to solve
and I figured I'd ask the list for assistance.
If I have code that looks something like this:
import daemon
class bar():
def func():
print "Hello World!\n"
def sigusr1_handler(signum,frame):
foo.func()
def main():
foo = bar()
context = daemon.DaemonContext()
context.signal_map = {
signal.SIGUSR1: sigusr1_handler
}
with context:
if (__name__="__main__"):
main()
Basically, this code becomes a daemon process and defines a signal handler
for SIGUSR1 which calls a method from class bar as instantiated by foo.
Unfortunately, this doesn't work. When the signal handler gets called,
python throws a NameError and says that global name "foo" is not defined.
anybody know how I can get the python interpreter to recognize the foo
variable in the signal handler? I tried using __main__.foo.func() but that
didn't work either.
Any help appreciated.
Thanks,
Braun Brelin
--
Irish Linux Users' Group mailing list
About this list : http://mail.linux.ie/mailman/listinfo/ilug
Who we are : http://www.linux.ie/
Where we are : http://www.linux.ie/ map/
