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

  • SEARCH
  • Home
  • 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 6701643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:57:31+00:00 2026-05-26T06:57:31+00:00

I am using tornado.httpclient.AsyncHTTPClient.fetch to fetch domains from list. When I put domains to

  • 0

I am using tornado.httpclient.AsyncHTTPClient.fetch to fetch domains from list. When I put domains to fetch with some big interval(500 for example) all works good, but when I decrease the inerval to 100, next exception occurs time to time:


Traceback (most recent call last):
  File "/home/crchemist/python-2.7.2/lib/python2.7/site-packages/tornado/simple_httpclient.py", line 289, in cleanup
    yield
  File "/home/crchemist/python-2.7.2/lib/python2.7/site-packages/tornado/stack_context.py", line 183, in wrapped
    callback(*args, **kwargs)
  File "/home/crchemist/python-2.7.2/lib/python2.7/site-packages/tornado/simple_httpclient.py", line 384, in _on_chunk_length
    self._on_chunk_data)
  File "/home/crchemist/python-2.7.2/lib/python2.7/site-packages/tornado/iostream.py", line 180, in read_bytes
    self._check_closed()
  File "/home/crchemist/python-2.7.2/lib/python2.7/site-packages/tornado/iostream.py", line 504, in _check_closed
    raise IOError("Stream is closed")
IOError: Stream is closed

What can be the reason of this behavior? Code looks like this:


def fetch_domain(domain):
    http_client = AsyncHTTPClient()
    request = HTTPRequest('http://' + domain,
       user_agent=CRAWLER_USER_AGENT)
    http_client.fetch(request, handle_domain)


class DomainFetcher(object):
    def __init__(self, domains_iterator):
        self.domains = domains_iterator

    def __call__(self):
        try:
            domain = next(self.domains)
        except StopIteration:
            domain_generator.stop()
            ioloop.IOLoop.instance().stop()
        else:
            fetch_domain(domain)

domain_generator = ioloop.PeriodicCallback(DomainFetcher(domains), 500)
domain_generator.start()

  • 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-05-26T06:57:32+00:00Added an answer on May 26, 2026 at 6:57 am

    note that tornado.ioloop.PeriodicCallback takes a cycle time in integer ms while the HTTPRequest object is configured with a connect_timeout and/or a request_timeout of float seconds (see doc).

    “Users browsing the Internet feel that responses are “instant” when delays are less than 100 ms from click to response” (from wikipedia) See this ServerFault question for normal latency values.

    IOError: Stream is closed is validly being raised to inform you that your connection timed out without completing, or more accurately, you called the callback manually on a pipe that wasn’t open yet. This is good, since it is not abnormal for latency to be > 100ms; if you expect your fetches to complete reliably you should raise this value.

    Once you’ve got your timeout set to something sane, consider wrapping your fetches in a try/except retry loop as this is a normal exception that you can expect to occur in production. Just be careful to set a retry limit!


    Since you’re using an async framework, why not let it handle the async callback itself instead of running said callback on a fixed interval? Epoll/kqueue are efficient and supported by this framework.

    import ioloop
    
    def handle_request(response):
        if response.error:
            print "Error:", response.error
        else:
            print response.body
        ioloop.IOLoop.instance().stop()
    
    http_client = httpclient.AsyncHTTPClient()
    http_client.fetch("http://www.google.com/", handle_request)
    ioloop.IOLoop.instance().start()
    

    ^ Copied verbatim from the doc.

    If you go this route, the only gotcha is to code your request queue so that you have a maximum open connections enforced. Otherwise you’re likely to end up with a race condition when doing serious scraping.

    It’s been ~1yr since I touched Tornado myself, so please let me know if there are inaccuracies in this response and I will revise.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I'm using a forever-frame to stream data from Tornado to a JavaScript client
I've been working on an embedded C/C++ project recently using the shell in Tornado
Using C# .NET 3.5 and WCF, I'm trying to write out some of the
Using C# and System.Data.SqlClient, is there a way to retrieve a list of parameters
I'm quite new to using Tornado Web as a web server, and am having
I'm using the Tornado framework (Python). I have the sluggable URLs working. But I
I'm using the Tornado framework (Python) on GAE. I'm still kind of new to
This is my first attempt to build a json webservice using the Tornado Framework
I'm using django-on-tornado to build an application that is similar to the chat applicatoin
I am using Apache and PHP as my front-end server and Tornado as my

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.