By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,268 Members | 1,371 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,268 IT Pros & Developers. It's quick & easy.

about second parameter of signal handler func.

P: n/a
Hi,

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?

Thank you!
--
LinuX Power
Mar 27 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Marco wrote:
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()?
>>help(signal)
[...]
*** IMPORTANT NOTICE ***
A signal handler function is called with two arguments:
the first is the signal number, the second is the interrupted
stack frame.
Regards,
Björn

--
BOFH excuse #253:

We've run out of licenses

Mar 27 '07 #2

P: n/a
En Tue, 27 Mar 2007 02:34:48 -0300, Bjoern Schliessmann
<us**************************@spamgourmet.comescri bió:
>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

Mar 27 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.