En Tue, 27 Mar 2007 02:34:48 -0300, Bjoern Schliessmann  
<[EMAIL PROTECTED]> escribió:

>> In C, a signal handler function has only one parameter, that is
>> signal number. But in Python(import signal), a signal handler
>> function has two parameters, the first is signal number, the
>> second is "frame"?
>>
>> What is "frame", please?
>
> Did you bother using help()?

The help text is of little help if you don't know what is it talking  
about...

The Python signal handler has additional information: you know *what* was  
being executed when the signal was caught (or nearly).
A little example:


import signal

def babies(n):
     if n<=1: return 1
     return adults(n-1)

def adults(n):
     if n<=1: return 0
     return adults(n-1)+babies(n-1)

def fibom(n):
     return adults(n)+babies(n)

def handler(signum, frame):
     print "At",frame.f_code.co_name, "in", frame.f_code.co_filename,  
"line", frame.f_lineno

# Press CTRL-C to see what's being executed
signal.signal(signal.SIGINT, handler)
for n in range(50):
     print n, fibom(n)

-- 
Gabriel Genellina

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to