0

I'm just starting out with autobahn python and I'm using the helper ApplicationRunner class to make a basic connection. My intent is to connect once, fire a message and then exit as that's all the script I'm writing needs to do. The issue I've run into is that it doesn't seem to be obvious how to shutdown the application once its been started, I've used the advice here to get access to the global reactor and call reactor.stop(), but I'm wondering if there's a better way. Check out my script below, all comments are welcome.

from autobahn.twisted.wamp import ApplicationRunner, ApplicationSession

class Example(ApplicationSession):
  def __init__(self, config=None):
    ApplicationSession.__init__(self, config)

  def onJoin(self, details):
    self.register(self)
    # publish something here
    from twisted.internet import reactor
    reactor.stop()

runner = ApplicationRunner(u"ws://example_address", u"example_realm")

try:
  runner.run(Example)
except Exception as e:
  print('Couldn\'t connect to WAMP router because: "{}"'.format(e))
Community
  • 1
  • 1
radman
  • 17,675
  • 11
  • 42
  • 58

0 Answers0