issue #106: add Service.__repr__, reply to bad calls

* Don't hang callers that fail validate_args(), instead tell them their
  message was rejected.
* Add Service.repr for nicer logging.
This commit is contained in:
David Wilson 2018-04-01 11:28:42 +01:00
parent 8f175bf7a8
commit f6d436783c
1 changed files with 7 additions and 0 deletions

View File

@ -82,6 +82,12 @@ class Service(object):
self.handle = self.recv.handle self.handle = self.recv.handle
self.running = True self.running = True
def __repr__(self):
return '%s.%s()' % (
self.__class__.__module__,
self.__class__.__name__,
)
def validate_args(self, args): def validate_args(self, args):
return ( return (
isinstance(args, dict) and isinstance(args, dict) and
@ -108,6 +114,7 @@ class Service(object):
isinstance(args, mitogen.core.CallError) or isinstance(args, mitogen.core.CallError) or
not self.validate_args(args)): not self.validate_args(args)):
LOG.warning('Received junk message: %r', args) LOG.warning('Received junk message: %r', args)
msg.reply(mitogen.core.CallError('Received junk message'))
return return
try: try: