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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:25:06+00:00 2026-06-17T22:25:06+00:00

I have some issue with too many Threads unfinished. I think that queue command

  • 0

I have some issue with too many Threads unfinished.
I think that queue command .join() just close queue and not the threads using it.

In my script I need to check 280k domains and for each domain get list of his MX records and obtain an IPv6 address of servers if it has it.

I used threads and thanks for them the script its many times faster. But there is a problem, although there is join() for the queue, number of alive threads is growing till an error occur that informs that cant create any new thread (limitation of OS?).

How can I terminate/close/stop/reset threads after each For loop when I am retrieving new domain from database?

Thread Class definition…

class MX_getAAAA_thread(threading.Thread):
    def __init__(self,queue,id_domain):
        threading.Thread.__init__(self)
        self.queue = queue
        self.id_domain = id_domain


    def run(self):
        while True:
            self.mx = self.queue.get()

            res = dns.resolver.Resolver()
            res.lifetime = 1.5
            res.timeout = 0.5

            try:
                answers = res.query(self.mx,'AAAA')
                ip_mx = str(answers[0])
            except:
                ip_mx = "N/A"

            lock.acquire()

            sql = "INSERT INTO mx (id_domain,mx,ip_mx) VALUES (" + str(id_domain) + ",'" + str(self.mx) + "','" + str(ip_mx) + "')"
            try:
                cursor.execute(sql)
                db.commit()
            except:
                db.rollback()

            print "MX" , '>>' , ip_mx, ' :: ', str(self.mx)

            lock.release()
            self.queue.task_done()

Thread class in use…
(The main For-loop is not here, this is just part of his body)

try:
    answers = resolver.query(domain, 'MX')

    qMX = Queue.Queue()
    for i in range(len(answers)):
        t = MX_getAAAA_thread(qMX,id_domain)
        t.setDaemon(True)
        threads.append(t)
        t.start()

    for mx in answers:
        qMX.put(mx.exchange)

    qMX.join()

except NoAnswer as e:
    print "MX - Error: No Answer"
except Timeout as etime:
    print "MX - Error: dns.exception.Timeout"

print "end of script"

I tried to:

for thread in threads:
            thread.join()

after the queue was done, but thread.join() never stops waiting, despite fact that there is no need to wait, because when queue.join() executes there is nothing to do for threads.

  • 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-17T22:25:08+00:00Added an answer on June 17, 2026 at 10:25 pm

    I do not see why you need a Queue in the first place.
    After all in your design every thread just processes one task.
    You should be able to pass that task to the thread on creation.
    This way you do not need a Queue and you get rid of the while-loop:

    class MX_getAAAA_thread(threading.Thread):
        def __init__(self, id_domain, mx):
            threading.Thread.__init__(self)
            self.id_domain = id_domain
            self.mx = mx
    

    Then you can rid of the while-loop inside the run-method:

    def run(self):
        res = dns.resolver.Resolver()
        res.lifetime = 1.5
        res.timeout = 0.5
    
        try:
            answers = res.query(self.mx,'AAAA')
            ip_mx = str(answers[0])
        except:
            ip_mx = "N/A"
    
        with lock:
            sql = "INSERT INTO mx (id_domain,mx,ip_mx) VALUES (" + str(id_domain) + ",'" + str(self.mx) + "','" + str(ip_mx) + "')"
            try:
                cursor.execute(sql)
                db.commit()
            except:
                db.rollback()
    
            print "MX" , '>>' , ip_mx, ' :: ', str(self.mx)
    

    Create one thread for each task

    for mx in answers:
        t = MX_getAAAA_thread(qMX, id_domain, mx)
        t.setDaemon(True)
        threads.append(t)
        t.start()
    

    and join them

    for thread in threads:
        thread.join()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that there are some threads have a similar issue with this thread.
I have some urgent issue which I could not find answer for across the
I have a weird issue. I have some icons that are being built based
I have an issue with some HTML displayed in Drupal, but I am not
I have an issue that has just recently come to my attention. We have
I have run into this issue too many times and need this to be
Good morning. I've been having this issue for some days and have been lokking
I have an issue while storing some special character values into db. For e.g.
i have an issue i could use some help with, i have python list
I have an issue with System.Threading.Timer. I am scheduling some actions using a time

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.