Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #82601

signal.signal handler arity check - PEP?

X-Received by 10.42.254.135 with SMTP id ne7mr41353608icb.30.1418836377579; Wed, 17 Dec 2014 09:12:57 -0800 (PST)
X-Received by 10.182.219.13 with SMTP id pk13mr9235obc.39.1418836377497; Wed, 17 Dec 2014 09:12:57 -0800 (PST)
Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!peer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!h15no24198421igd.0!news-out.google.com!h6ni559igv.0!nntp.google.com!h15no24198413igd.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups comp.lang.python
Date Wed, 17 Dec 2014 09:12:57 -0800 (PST)
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=24.196.71.171; posting-account=ftUzqAkAAAB0ziTgdWrXKVPsILGert2L
NNTP-Posting-Host 24.196.71.171
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <79e004d7-67f7-4fbf-a5aa-4d422fd95b30@googlegroups.com> (permalink)
Subject signal.signal handler arity check - PEP?
From Mike Pomraning <mjp@pilcrow.madison.wi.us>
Injection-Date Wed, 17 Dec 2014 17:12:57 +0000
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
X-Received-Bytes 2029
X-Received-Body-CRC 2378651065
Xref csiph.com comp.lang.python:82601

Show key headers only | View raw


It strikes me as oddly dangerous that signal.signal() accepts callable handlers of the wrong arity:

    def timeout_cleanup():
      ...

    signal.signal(signal.SIGALRM, timeout_cleanup)       # I desire a TypeError here
    signal.alarm(PROCESS_TIMEOUT)

    ... time passes ...

    TypeError: timeout_cleanup() takes 0 positional arguments but 2 were given

(Similar TypeError with different text under python 2.)

The downside to current behavior is that the coding error is revealed only under certain conditions at runtime.  In the example above, you don't know that your seatbelt is defective until you need it.

Does anyone disagree with modifying signal.signal's behavior to raise a TypeError when given a user-defined handler of the wrong arity?  Any code relying on this behavior is, IMO, contrived beyond plausibility.  However, this change might break code not yet known to be incorrect.

If no disagreements, patch or PEP?

-Mike

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

signal.signal handler arity check - PEP? Mike Pomraning <mjp@pilcrow.madison.wi.us> - 2014-12-17 09:12 -0800

csiph-web