How to get tornado object?
<p>I want to get value of a tornado object with key</p>

<p>This is my code : </p>

<pre><code>beanstalk = beanstalkt.Client(host='host', port=port)
beanstalk.connect()
print("ok1")

beanstalk.watch('contracts')
stateTube = beanstalk.stats_tube('contracts', callback=show)
print("ok2")

ioloop = tornado.ioloop.IOLoop.instance()
ioloop.start()

print("ok3")
</code></pre>

<p>And this is the function `show()``</p>

<pre><code>def show(s):
    pprint(s['current-jobs-ready'])
    ioloop.stop
</code></pre>

<p>When I look at the documentation I found this : 
<a href="http://i.stack.imgur.com/qUJqb.png" rel="nofollow"><img src="http://i.stack.imgur.com/qUJqb.png" alt="enter image description here"></a></p>

<p>And when I excecute this code, I have this :</p>

<pre><code>ok1
ok2
3
</code></pre>

<p>In fact I have the result I wanted "3" but I don't understand why my program continue to running? Whythe ioloop doesn't close? I don't have <code>ok3</code>when I compile how can I do to close the ioloop and have <code>ok3</code>?</p>

<p><code>beanstalk.stats_tube</code> is async, it returns a <code>Future</code> which represents a future result that has not yet been resolved.</p>

<p>As <a href="https://github.com/nephics/beanstalkt" rel="nofollow">the README says</a>, Your callback <code>show</code> will be executed with a dict that contains the resolved result. So you could define <code>show</code> like:</p>

<pre><code>def show(stateTube):
    pprint(stateTube['current-job-ready'])

beanstalk.stats_tube('contracts', callback=show)

from tornado.ioloop import IOLoop
IOLoop.current().start()
</code></pre>

<p>Note that you pass <code>show</code>, not <code>show()</code>: you're passing the function itself, not calling the function and passing its return value.</p>

<p>The other way to resolve a Future, besides passing a callback, is to use it in a coroutine:</p>

<pre><code>from tornado import gen
from tornado.ioloop import IOLoop

@gen.coroutine
def get_stats():
    stateTube = yield beanstalk.stats_tube('contracts')
    pprint(stateTube['current-job-ready'])

loop = IOLoop.current()
loop.spawn_callback(get_stats)
loop.start()
</code></pre>

python object tornado beanstalk