Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8729891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:54:39+00:00 2026-06-13T08:54:39+00:00

Using Tornado, I have a Get request that takes a long time as it

  • 0

Using Tornado, I have a Get request that takes a long time as it makes many requests to another web service and processes the data, could take minutes to fully complete. I don’t want this to block the entire web server from responding to other requests, which it currently does.

As I understand it, Tornado is single threaded and executes each request synchronously, even though it handles them asynchronously (still confused on that bit). There are parts of the long process that could be pause points to allow the server to handle other requests (possible solution?). I’m running it on Heroku with a single worker, so not sure how that translates into spawning a new thread or multiprocessing, which I have no experience in with python.

Here is what I’m trying to do: the client makes the get call to start the process, then I loop through another get call every 5 seconds to check the status and update the page with new information (long polling would also work but running into the same issue). Problem is that starting the long process blocks all new get requests (or new long polling sessions) until it completes.

Is there an easy way to kick off this long get call and not have it block the entire web server in the process? Is there anything I can put in the code to say.. “pause, go handle pending requests then continue on”?

I need to initiate a get request on ProcessHandler. I then need to continue to be able to query StatusHandler while ProcessHandler is running.

Example:

class StatusHandler(tornado.web.RequestHandler):
    @tornado.web.asynchronous
    def get(self):
       self.render("status.html")

class ProcessHandler(tornado.web.RequestHandler):
    @tornado.web.asynchronous
    def get(self):
       self.updateStatus("0")
       result1 = self.function1()
       self.updateStatus("1")
       result2 = self.function2(result1)
       self.updateStatus("2")
       result3 = self.function3(result2)
       self.updateStatus("3")
       self.finish()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:54:40+00:00Added an answer on June 13, 2026 at 8:54 am

    Here’s a complete sample Tornado app that uses the Async HTTP client and the gen.Task module to make things simple.

    If you read more about gen.Task in the docs you’ll see that you can actually dispatch multiple requests at the same time. This is using the core idea of Tornado where everything is no blocking and still maintaining a single process.

    Update: I’ve added a Thread handler to demonstrate how you could dispatch work into a second thread and receive the callback() when it’s done.

    import os
    import threading
    import tornado.options
    import tornado.ioloop
    import tornado.httpserver
    import tornado.httpclient
    import tornado.web
    from tornado import gen
    from tornado.web import asynchronous
    
    tornado.options.define('port', type=int, default=9000, help='server port number (default: 9000)')
    tornado.options.define('debug', type=bool, default=False, help='run in debug mode with autoreload (default: False)')
    
    class Worker(threading.Thread):
       def __init__(self, callback=None, *args, **kwargs):
            super(Worker, self).__init__(*args, **kwargs)
            self.callback = callback
    
       def run(self):
            import time
            time.sleep(10)
            self.callback('DONE')
    
    class Application(tornado.web.Application):
        def __init__(self):
            handlers = [
                (r"/", IndexHandler),
                (r"/thread", ThreadHandler),
            ]
            settings = dict(
                static_path = os.path.join(os.path.dirname(__file__), "static"),
                template_path = os.path.join(os.path.dirname(__file__), "templates"),
                debug = tornado.options.options.debug,
            )
            tornado.web.Application.__init__(self, handlers, **settings)
    
    class IndexHandler(tornado.web.RequestHandler):
        client = tornado.httpclient.AsyncHTTPClient()
    
        @asynchronous
        @gen.engine
        def get(self):
            response = yield gen.Task(self.client.fetch, "http://google.com")
    
            self.finish("Google's homepage is %d bytes long" % len(response.body))
    
    class ThreadHandler(tornado.web.RequestHandler):
        @asynchronous
        def get(self):
            Worker(self.worker_done).start()
    
        def worker_done(self, value):
            self.finish(value)
    
    def main():
        tornado.options.parse_command_line()
        http_server = tornado.httpserver.HTTPServer(Application())
        http_server.listen(tornado.options.options.port)
        tornado.ioloop.IOLoop.instance().start()
    
    if __name__ == "__main__":
        main()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Tornado and I have the following code: class UserHandler(RequestHandler): def get(self):
I'm using tornado to fetch many web pages asyncroniously using HTTP proxy . So,
I have a basic app set up using Backbone.js and Tornado Web. When I
I'm using SSH to remotely launch Tornado on Amazon Web Service. It works fine
I'm using tornado, and have a bunch of handlers that map to different urls.
When running a test using the Tornado AsyncHTTPTestCase I'm getting a stack trace that
I'm building a simple web application in tornado.web using mongodb as the backend. 90%
Using tornado, I want to create a bit of middleware magic that ensures that
I've been playing around a bit with the Tornado web server and have come
I'm using the Tornado framework (Python). I have the sluggable URLs working. But I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.