Skip to content

Event: remove ev_timeout() definition #498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions lib/ClusterShell/Event.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ class EventHandler(object):
Derived class should implement any of the following methods to listen for
:class:`.Worker`, :class:`.EnginePort` or :class:`.EngineTimer` events.
If not implemented, the default behavior is to do nothing.

NOTE: ``ev_timeout(self, worker)`` was removed from this class definition
in ClusterShell 1.9. For compatibility, it is still called if defined by
subclasses. Use ``ev_close()`` instead and check whether its argument
``timedout`` is ``True``, which means that the :class:`.Worker` has timed
out.
"""

### Worker events
Expand Down Expand Up @@ -122,23 +128,14 @@ def ev_hup(self, worker, node, rc):
command return codes)
"""

def ev_timeout(self, worker):
"""
Called to indicate that a worker has timed out (worker timeout only).

[DEPRECATED] use ev_close instead and check if timedout is True

:param worker: :class:`.Worker` object
"""

def ev_close(self, worker, timedout):
"""
Called to indicate that a worker has just finished.

.. warning:: The signature of :meth:`EventHandler.ev_close` changed
in ClusterShell 1.8, please update your :class:`.EventHandler`
derived classes to add the timedout argument. Please use this
argument instead of the method ``ev_timeout``.
argument instead of the old method ``ev_timeout()``.

:param worker: :class:`.Worker` derived object
:param timedout: boolean set to True if the worker has timed out
Expand Down
13 changes: 13 additions & 0 deletions tests/TaskEventTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,19 @@ def test_simple_event_handler(self):
self.run_task_and_catch_warnings(task)
eh.do_asserts_read_notimeout()

def test_simple_event_handler_with_timeout(self):
"""test simple event handler with timeout"""
task = task_self()

eh = TestHandler()

task.shell("/bin/sleep 3", handler=eh, timeout=2)

# verify that no warnings are generated
self.run_task_and_catch_warnings(task, 0)

eh.do_asserts_timeout()

def test_simple_event_handler_with_timeout_legacy(self):
"""test simple event handler with timeout (legacy)"""
task = task_self()
Expand Down