Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for non-RequestHandler objects? #4

Open
diranged opened this issue Aug 14, 2014 · 0 comments
Open

Support for non-RequestHandler objects? #4

diranged opened this issue Aug 14, 2014 · 0 comments

Comments

@diranged
Copy link

The current code does not support patching anything that isnt a subclass of a RequestHandler object due to the use of the @tornado.web.asynchronous decorator.

test.py

import logging

from tornado import ioloop
from tornado import gen

from trequests import setup_session
from tornalet import tornalet

from rightscale import commands as rightscale_commands
from rightscale import util as rightscale_util

logging.basicConfig(level=logging.DEBUG)
log = logging.getLogger(name)

Tell requests to use our AsyncHTTPadapter for the default

session instance, you can also pass you own through

setup_session()

class RightScaleAPI(object):
def init(self, token, api='http://my.rightscale.com'):
self._token = token
self._api = api

@tornalet
def find(self, name, exact=True):
    # Blocking login and then blocking search call
    self._obj = rightscale.RightScale(refresh_token=self._token, api_endpoint=self._api)
    sa = rightscale_util.find_by_name(self._obj.server_arrays, name, exact=exact)

@gen.coroutine
def main():
actions = []
res = None
for x in xrange(1,10):
actions.append(RightScaleAPI('asdf').find('staging'))
res = yield actions
raise gen.Return(True)

if name == 'main':
try:
log.info('Starting up')
ioloop.IOLoop.instance().run_sync(main)
log.info('Done')
except KeyboardInterrupt:
log.info('CTRL-C caught, shutting down')
cleanup()

failure

INFO:main:Starting up
Traceback (most recent call last):
File "test.py", line 51, in
ioloop.IOLoop.instance().run_sync(main)
File "/Users/diranged/git/Nextdoor/kingpin/.venv/lib/python2.7/site-packages/tornado-3.1.1-py2.7.egg/tornado/ioloop.py", line 370, in run_sync
return future_cell[0].result()
File "/Users/diranged/git/Nextdoor/kingpin/.venv/lib/python2.7/site-packages/tornado-3.1.1-py2.7.egg/tornado/concurrent.py", line 129, in result
raise_exc_info(self.__exc_info)
File "/Users/diranged/git/Nextdoor/kingpin/.venv/lib/python2.7/site-packages/tornado-3.1.1-py2.7.egg/tornado/gen.py", line 221, in wrapper
runner.run()
File "/Users/diranged/git/Nextdoor/kingpin/.venv/lib/python2.7/site-packages/tornado-3.1.1-py2.7.egg/tornado/gen.py", line 507, in run
yielded = self.gen.send(next)
File "test.py", line 39, in main
actions.append(RightScaleAPI('asdf').find('staging'))
File "/Users/diranged/git/Nextdoor/kingpin/.venv/lib/python2.7/site-packages/tornado-3.1.1-py2.7.egg/tornado/web.py", line 1293, in wrapper
if self.application._wsgi:
AttributeError: 'RightScaleAPI' object has no attribute 'application'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant