Skip to content

Commit 293ad48

Browse files
authored
Event: remove ev_timeout() definition (#498)
Commit 269ddbd for #358 introduced a DeprecationWarning for ev_timeout() which doesn't work without removing the method definition from EventHandler. Remove the definition from the class, add specific test and update documentation.
1 parent 269ddbd commit 293ad48

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

lib/ClusterShell/Event.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ class EventHandler(object):
3333
Derived class should implement any of the following methods to listen for
3434
:class:`.Worker`, :class:`.EnginePort` or :class:`.EngineTimer` events.
3535
If not implemented, the default behavior is to do nothing.
36+
37+
NOTE: ``ev_timeout(self, worker)`` was removed from this class definition
38+
in ClusterShell 1.9. For compatibility, it is still called if defined by
39+
subclasses. Use ``ev_close()`` instead and check whether its argument
40+
``timedout`` is ``True``, which means that the :class:`.Worker` has timed
41+
out.
3642
"""
3743

3844
### Worker events
@@ -122,23 +128,14 @@ def ev_hup(self, worker, node, rc):
122128
command return codes)
123129
"""
124130

125-
def ev_timeout(self, worker):
126-
"""
127-
Called to indicate that a worker has timed out (worker timeout only).
128-
129-
[DEPRECATED] use ev_close instead and check if timedout is True
130-
131-
:param worker: :class:`.Worker` object
132-
"""
133-
134131
def ev_close(self, worker, timedout):
135132
"""
136133
Called to indicate that a worker has just finished.
137134
138135
.. warning:: The signature of :meth:`EventHandler.ev_close` changed
139136
in ClusterShell 1.8, please update your :class:`.EventHandler`
140137
derived classes to add the timedout argument. Please use this
141-
argument instead of the method ``ev_timeout``.
138+
argument instead of the old method ``ev_timeout()``.
142139
143140
:param worker: :class:`.Worker` derived object
144141
:param timedout: boolean set to True if the worker has timed out

tests/TaskEventTest.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,19 @@ def test_simple_event_handler(self):
189189
self.run_task_and_catch_warnings(task)
190190
eh.do_asserts_read_notimeout()
191191

192+
def test_simple_event_handler_with_timeout(self):
193+
"""test simple event handler with timeout"""
194+
task = task_self()
195+
196+
eh = TestHandler()
197+
198+
task.shell("/bin/sleep 3", handler=eh, timeout=2)
199+
200+
# verify that no warnings are generated
201+
self.run_task_and_catch_warnings(task, 0)
202+
203+
eh.do_asserts_timeout()
204+
192205
def test_simple_event_handler_with_timeout_legacy(self):
193206
"""test simple event handler with timeout (legacy)"""
194207
task = task_self()

0 commit comments

Comments
 (0)