Commit 9a7f7061 authored by Jason Madden's avatar Jason Madden

Check that the handler for gevent.hub.signal is callable at construction time. Fixes #818.

parent c02a1bdd
...@@ -111,6 +111,9 @@ Other Changes ...@@ -111,6 +111,9 @@ Other Changes
while it's being read from or written to in a different greenlet is while it's being read from or written to in a different greenlet is
less likely to raise a :exc:`TypeError` instead of a less likely to raise a :exc:`TypeError` instead of a
:exc:`ValueError`. Reported in :issue:`800` by Kevin Chen. :exc:`ValueError`. Reported in :issue:`800` by Kevin Chen.
- :class:`gevent.hub.signal` (aka :func:`gevent.signal`) now verifies
that its `handler` argument is callable, raising a :exc:`TypeError`
if it isn't. Reported in :issue:`818` by Peter Renström.
1.1.1 (Apr 4, 2016) 1.1.1 (Apr 4, 2016)
=================== ===================
......
...@@ -175,6 +175,10 @@ Signals ...@@ -175,6 +175,10 @@ Signals
is replacing this name. This alias will be removed in a is replacing this name. This alias will be removed in a
future release. future release.
.. versionchanged:: 1.2a1
The *handler* is required to be callable at construction time.
.. This is also in the docstring of gevent.hub.signal, which is the .. This is also in the docstring of gevent.hub.signal, which is the
actual callable invoked actual callable invoked
......
...@@ -228,6 +228,9 @@ class signal(object): ...@@ -228,6 +228,9 @@ class signal(object):
This may not operate correctly with SIGCHLD if libev child watchers This may not operate correctly with SIGCHLD if libev child watchers
are used (as they are by default with os.fork). are used (as they are by default with os.fork).
.. versionchanged:: 1.2a1
The ``handler`` argument is required to be callable at construction time.
""" """
# XXX: This is manually documented in gevent.rst while it is aliased in # XXX: This is manually documented in gevent.rst while it is aliased in
...@@ -236,6 +239,9 @@ class signal(object): ...@@ -236,6 +239,9 @@ class signal(object):
greenlet_class = None greenlet_class = None
def __init__(self, signalnum, handler, *args, **kwargs): def __init__(self, signalnum, handler, *args, **kwargs):
if not callable(handler):
raise TypeError("signal handler must be callable.")
self.hub = get_hub() self.hub = get_hub()
self.watcher = self.hub.loop.signal(signalnum, ref=False) self.watcher = self.hub.loop.signal(signalnum, ref=False)
self.watcher.start(self._start) self.watcher.start(self._start)
......
...@@ -18,6 +18,9 @@ if hasattr(signal, 'SIGALRM'): ...@@ -18,6 +18,9 @@ if hasattr(signal, 'SIGALRM'):
error_fatal = False error_fatal = False
__timeout__ = 5 __timeout__ = 5
def test_handler(self):
self.assertRaises(TypeError, gevent.signal, signal.SIGALRM, 1)
def test_alarm(self): def test_alarm(self):
sig = gevent.signal(signal.SIGALRM, raise_Expected) sig = gevent.signal(signal.SIGALRM, raise_Expected)
assert sig.ref is False, repr(sig.ref) assert sig.ref is False, repr(sig.ref)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment