Skip to content Skip to sidebar Skip to footer

Tornado How To Return Error Exception?

I want to run a method I know this method doesn't work and I want to get the error returned by the method. This is my code : def is_connect(s): print('ok connection') pri

Solution 1:

Here's where reading the code helps. In beanstalkt 0.6's connect, it creates an IOStream to connect to the server:

https://github.com/nephics/beanstalkt/blob/v0.6.0/beanstalkt/beanstalkt.py#L108

It registers your callback to be executed on success, but if the connection fails it'll just call Client._reconnect once per second forever. I think you should open a feature request in their GitHub project asking for an error-notification system for connect. With the current beanstalkt implementation, you just have to decide how long you're willing to wait for success:

import sys
from datetime import timedelta

from tornado.ioloop import IOLoop

def is_connect(s):
    print("ok connection")
    print(s)
    loop.remove_timeout(timeout)
    # Do something with Beanstalkd....

def connection_failed():
    print(sys.stderr, "Connection failed!")
    # Could call IOLoop.stop() or just quit.
    sys.exit(1)

loop = IOLoop.current()
timeout = loop.add_timeout(timedelta(seconds=1), connection_failed)
beanstalk.connect(callback=is_connect)
loop.start()

Post a Comment for "Tornado How To Return Error Exception?"