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 9175997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:00:38+00:00 2026-06-17T17:00:38+00:00

I’m writing a very basic multi-threaded web crawler written in Python, and using a

  • 0

I’m writing a very basic multi-threaded web crawler written in Python, and using a While loop for the function that crawls a page and extract urls, as follows:

def crawl():
    while True:
        try:
            p = Page(pool.get(True, 10))
        except Queue.Empty:
            continue

        # then extract urls from a page and put new urls into the queue

(The complete source code is here in another question: Multi-threaded Python Web Crawler Got Stuck)

Now ideally, I want to add a condition to the While loop, to make the while loop exit when:

  1. the pool (the Queue object that stores the urls) is empty, and;

  2. all threads are blocking, waiting to get a url from the queue (which means no threads is putting new urls into the pool, so keeping them waiting doesn’t make sense and will make my program stuck.)

For example, something like:

#thread-1.attr == 1 means the thread-1 is blocking. 0 means not blocking

while not (pool.empty() and (thread-1.attr == 1 and thread-2.attr == 1 and ...)):
    #do the crawl stuff

So I’m wondering if there is a away for a thread to check what other active threads are doing, or the status or value of an attribute of other active threads.

I have read the official document on threading.Event(), but still can’t figure it out.

Hope someone here can point me the way 🙂

Thank you very much!

Marcus

  • 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-17T17:00:39+00:00Added an answer on June 17, 2026 at 5:00 pm

    You can try to implement what you want from scratch, there is different solutions that come to my mind right now:

    • Using threading.enumerate() to check if there is a thread that are still alive.
    • Try to implement a threading pool which let you know which thread a are still alive which are returned to the pool, this have also the benefit of limiting the number of threads that crawl third party website (check here for example).

    If you want to not reinvent the wheel you can use existing libraries that implement a thread pool or you can also check gevent which use green thread and offer also a thread pool, i have implemented something similar to this using something like:

    while 1:
        try:
            url = queue.get_nowait()
        except Empty:
            # Check that all threads are done.
            if pool.free_count() == pool.size:
                break
        ...
    

    You can also write a sentinel object to your queue that mark the finish of crawling and exist your main loop and wait for threads to finish (using a pool for example).

    while 1:
        try:
            url = queue.get_nowait()
            # StopIteration mark that no url will be added to the queue anymore.
            if url is StopIteration:
                 break
        except Empty:
            continue
        ...
    pool.join()
    

    You can choose the one that you prefer, and hopefully this was helpful.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am using JSon response to parse title,date content and thumbnail images and place
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only

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.