1

I need to store the output of a get function of a request handler before running the tornado server from outside the application.

Example:-

class Test(RequestHandler):

  def get:
       print "safds"'

   ....
   ...

I need to call get function without tornado loop server from outside. Is it possible ? Is there any turnaround. Please help.

Thanks

rohitsakala
  • 379
  • 3
  • 15
  • Can you elaborate the reason you want to do that? It will may help us to understand your reasoning for doing that and therefore provide an appropriate solution. Depending on you reason, you may find RequestHandler.prepare -http://www.tornadoweb.org/en/stable/_modules/tornado/web.html#RequestHandler.prepare , helpful for your particular request. Although it is called from isnide of tornado loop serve, it can access `get` input before it is executed. – afxentios Dec 15 '16 at 08:17
  • @rohitsakala It's possible, but it requires a lot of extra code, because you need an instance of your `RequestHandler` for that. Why do you want to do it? It might be a better idea to put logic, that generates the data you're trying to get this way from `get` method in a separate method/class (and may be even another module, like `model` or `controller`), and then call this method inside `get` in `RequestHandler` and in your code. – Nikita Dec 15 '16 at 09:02

1 Answers1

0

If you happen to end up reading this question, I knew that I had to somehow create an instance of my handler to be able to call the post or get function inside. After looking at the RequestHandler's implementation, I came up with the following snippet:

from tornado.web import Application
from tornado.httpserver import HTTPRequest

mock_app = Mock(spec=Application)
request = HTTPRequest(
        method='GET', uri='/', headers=None, body=None
)
response = Handler(mock_app, request).get()
nima
  • 1,645
  • 9
  • 18