Skip to content

Commit 61c8af3

Browse files
committed
EventHandler: reinstate ev_error and ev_timeout (as deprecated)
Both EventHandler.ev_error() and EventHandler.ev_timeout() methods were mistakenly removed from 1.8.0, leading to possible issues with EventHandler subclasses. This patch reinstates both methods to improve backward compatibility but add DEPRECATED notes in the documentation. Closes #377 Change-Id: I1d12e3ab6b190e91dca32745d83145d7fe5bb75b
1 parent 4351981 commit 61c8af3

File tree

4 files changed

+44
-17
lines changed

4 files changed

+44
-17
lines changed

lib/ClusterShell/Event.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,20 @@ def ev_read(self, worker, node, sname, msg):
7272
:param msg: message
7373
"""
7474

75+
def ev_error(self, worker):
76+
"""
77+
Called to indicate that a worker has error to read on stderr from
78+
a specific node (or key).
79+
80+
[DEPRECATED] use ev_read instead and test if sname is 'stderr'
81+
82+
:param worker: :class:`.Worker` object
83+
84+
Available worker attributes:
85+
* :attr:`.Worker.current_node` - node (or key)
86+
* :attr:`.Worker.current_errmsg` - read error message
87+
"""
88+
7589
def ev_written(self, worker, node, sname, size):
7690
"""
7791
Called to indicate that some writing has been done by the worker to a
@@ -106,6 +120,15 @@ def ev_hup(self, worker, node, rc):
106120
command return codes)
107121
"""
108122

123+
def ev_timeout(self, worker):
124+
"""
125+
Called to indicate that a worker has timed out (worker timeout only).
126+
127+
[DEPRECATED] use ev_close instead and check if timedout is True
128+
129+
:param worker: :class:`.Worker` object
130+
"""
131+
109132
def ev_close(self, worker, timedout):
110133
"""
111134
Called to indicate that a worker has just finished.

lib/ClusterShell/Worker/Exec.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ def _check_fini(self):
376376
self._close_count += 1
377377
assert self._close_count <= len(self._clients)
378378
if self._close_count == len(self._clients) and self.eh is not None:
379+
# also use hasattr check because ev_timeout was missing in 1.8.0
379380
if self._has_timeout and hasattr(self.eh, 'ev_timeout'):
380381
# Legacy ev_timeout event
381382
self.eh.ev_timeout(self)

lib/ClusterShell/Worker/Tree.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ def _check_fini(self, gateway=None):
462462
if self._close_count >= self._target_count:
463463
handler = self.eh
464464
if handler:
465+
# also use hasattr check because ev_timeout was missing in 1.8.0
465466
if self._has_timeout and hasattr(handler, 'ev_timeout'):
466467
handler.ev_timeout(self)
467468
_eh_sigspec_invoke_compat(handler.ev_close, 2, self,

lib/ClusterShell/Worker/Worker.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ def _eh_sigspec_invoke_compat(method, argc_legacy, *args):
5151
# Assume new signature (2.x)
5252
return method(*args)
5353

54+
def _eh_sigspec_ev_read_17(ev_read):
55+
"""Helper function to check whether ev_read has the old 1.7 signature."""
56+
return len(getfullargspec(ev_read)[0]) == 2
57+
5458

5559
class WorkerException(Exception):
5660
"""Generic worker exception."""
@@ -252,19 +256,18 @@ def _on_node_msgline(self, node, msg, sname):
252256
if sname == self.SNAME_STDERR:
253257
self.current_errmsg = msg
254258
if self.eh is not None:
255-
# check for deprecated ev_error (< 1.8)
256-
if hasattr(self.eh, 'ev_error'):
259+
# call old ev_error for compat (default is no-op)
260+
if hasattr(self.eh, 'ev_error'): # missing in 1.8.0!
257261
self.eh.ev_error(self)
258-
else:
259-
# ev_read: ignore old signature (< 1.8)
260-
if len(getfullargspec(self.eh.ev_read)[0]) != 2:
261-
### FUTURE (2.x) ###
262-
self.eh.ev_read(self, node, sname, msg)
262+
# /!\ NOT elif
263+
if not _eh_sigspec_ev_read_17(self.eh.ev_read):
264+
### FUTURE (2.x) ###
265+
self.eh.ev_read(self, node, sname, msg)
263266
else:
264267
self.current_msg = msg
265268
if self.eh is not None:
266269
# ev_read: check for old signature first (< 1.8)
267-
if len(getfullargspec(self.eh.ev_read)[0]) == 2:
270+
if _eh_sigspec_ev_read_17(self.eh.ev_read):
268271
self.eh.ev_read(self)
269272
else:
270273
### FUTURE (2.x) ###
@@ -574,20 +577,18 @@ def _on_msgline(self, key, msg, sname):
574577
if sname == 'stderr':
575578
self.current_errmsg = msg
576579
if self.eh is not None:
577-
# this part is tricky to support backward compatibility...
578-
# check for deprecated ev_error (< 1.8)
579-
if hasattr(self.eh, 'ev_error'):
580+
# call old ev_error for compat (default is no-op)
581+
if hasattr(self.eh, 'ev_error'): # missing in 1.8.0!
580582
self.eh.ev_error(self)
581-
else:
582-
# ev_read: ignore old signature (< 1.8)
583-
if len(getfullargspec(self.eh.ev_read)[0]) != 2:
584-
### FUTURE (2.x) ###
585-
self.eh.ev_read(self, key, sname, msg)
583+
# /!\ NOT elif
584+
if not _eh_sigspec_ev_read_17(self.eh.ev_read):
585+
### FUTURE (2.x) ###
586+
self.eh.ev_read(self, key, sname, msg)
586587
else:
587588
self.current_msg = msg
588589
if self.eh is not None:
589590
# ev_read: check for old signature first (< 1.8)
590-
if len(getfullargspec(self.eh.ev_read)[0]) == 2:
591+
if _eh_sigspec_ev_read_17(self.eh.ev_read):
591592
self.eh.ev_read(self)
592593
else:
593594
### FUTURE (2.x) ###
@@ -598,6 +599,7 @@ def _on_timeout(self, key):
598599
self.task._timeout_add(self, key)
599600

600601
# trigger timeout event (deprecated in 1.8+)
602+
# also use hasattr check because ev_timeout was missing in 1.8.0
601603
if self.eh and hasattr(self.eh, 'ev_timeout'):
602604
self.eh.ev_timeout(self)
603605

0 commit comments

Comments
 (0)