Add useful watcher '__repr__' function

When a workers watchers are iterated over and
say printed to stderr/stdout the default '__repr__'
doesn't provide much value; so instead of the default
provide our own that adds slightly more value.

Change-Id: I8f82a732ad3d9f0ce0ec5857d5d883b3b5f2ff1d
This commit is contained in:
Joshua Harlow 2015-10-06 17:08:48 -07:00
parent b96691eb03
commit 08f0d10a25
1 changed files with 12 additions and 0 deletions

View File

@ -46,9 +46,21 @@ IMMEDIATE = 'immediate'
class Watcher(object):
"""A **read-only** object representing a periodics callbacks activities."""
_REPR_MSG_TPL = ("<Watcher object at 0x%(ident)x "
"("
"runs=%(runs)s,"
" successes=%(successes)s,"
" failures=%(failures)s,"
" elapsed=%(elapsed)0.2f,"
" elapsed_waiting=%(elapsed_waiting)0.2f"
")>")
def __init__(self, metrics):
self._metrics = metrics
def __repr__(self):
return self._REPR_MSG_TPL % dict(ident=id(self), **self._metrics)
@property
def runs(self):
"""How many times the periodic callback has been ran."""