From f66411e62b3acd715e9f978f2331a7f564adcc42 Mon Sep 17 00:00:00 2001 From: izderadicka Date: Thu, 26 May 2016 18:06:04 +0200 Subject: [PATCH] small fixes in example --- examples/asyncio/wamp/rawsocket/frontend.py | 2 +- examples/asyncio/wamp/rawsocket/runner.py | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/examples/asyncio/wamp/rawsocket/frontend.py b/examples/asyncio/wamp/rawsocket/frontend.py index d23a0dd2..ba63f696 100644 --- a/examples/asyncio/wamp/rawsocket/frontend.py +++ b/examples/asyncio/wamp/rawsocket/frontend.py @@ -35,7 +35,7 @@ class MyComponent(ApplicationSession): if __name__ == '__main__': level = 'info' - if len(sys.argv) > 1 and sys.argv[1] == ' debug': + if len(sys.argv) > 1 and sys.argv[1] == 'debug': level = 'debug' runner = ApplicationRunnerRawSocket( "tcp://localhost:9090", diff --git a/examples/asyncio/wamp/rawsocket/runner.py b/examples/asyncio/wamp/rawsocket/runner.py index cf5e0b45..211d4e58 100644 --- a/examples/asyncio/wamp/rawsocket/runner.py +++ b/examples/asyncio/wamp/rawsocket/runner.py @@ -78,6 +78,18 @@ class ApplicationRunnerRawSocket(object): txaio.use_asyncio() txaio.config.loop = loop + try: + loop.add_signal_handler(signal.SIGTERM, loop.stop) + except NotImplementedError: + # signals are not available on Windows + pass + + def handle_error(loop, context): + self.log.error('Application Error: {err}', err=context) + loop.stop() + + loop.set_exception_handler(handle_error) + if is_unix: coro = loop.create_unix_connection(transport_factory, parsed_url.path) else: @@ -86,17 +98,11 @@ class ApplicationRunnerRawSocket(object): txaio.start_logging(level=logging_level) # @UndefinedVariable - try: - loop.add_signal_handler(signal.SIGTERM, loop.stop) - except NotImplementedError: - # signals are not available on Windows - pass - try: loop.run_forever() except KeyboardInterrupt: pass - self.log('Left main loop waiting for completiotion') + self.log.debug('Left main loop waiting for completion') # give Goodbye message a chance to go through, if we still # have an active session # it's not working now - because protocol is_closed must return Future