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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:28:18+00:00 2026-06-18T07:28:18+00:00

I have a problem with my program. I managed to locate the source of

  • 0

I have a problem with my program.

I managed to locate the source of problem. Problem is in the method “checkPort”. Without it the standard textbook methods for closing/terminating threads works very well.

Am I missing something? Is in the checkPort method something that prevents to successfully join the threads? Its always stuck on thread.join().

Part of the main program:

try:
    queue = Queue.Queue()

    for i in range(MAX_THREAD_COUNT):
        t = checkPort_IPv6_thread(queue)
        t.daemon = True
        threads.append(t)
        t.start()

    cur.execute("SELECT * FROM ipv6")
    results = cur.fetchall()
    for row in results:
        queue.put((row[0], row[2]))

    queue.join()

    for thread in threads:
        thread.stop()
        thread.join()

except Exception as e:
    sys.stderr.write("Error: " + str(e))
    print

print "\nChecking ports for IPv6 - DONE"

Here is the thread class where I call checkPort method:

class checkPort_IPv6_thread(threading.Thread):
    def __init__(self,queue):
        threading.Thread.__init__(self)
        self.queue = queue
        self.keepRunning = True

    def run(self):
        while self.keepRunning:
            args = self.queue.get()
            id = args[0]
            address = args[1]
            port443 = 0
            port21 = 0 
            port80 = 0 

            #---------------- Check ports for IPv6 ----------------
            if str(address) != "N/A":
                port443 = checkPort("TCP",str(address), 443)
                port21 = checkPort("TCP",str(address), 21)
                port80 = checkPort("TCP",str(address), 80)

            lock.acquire()
            try:
                cur.execute("UPDATE ipv6 SET port_443=" + str(port443) + " WHERE id_ipv6 =" + str(id))
                cur.execute("UPDATE ipv6 SET port_21=" + str(port21) + " WHERE id_ipv6 =" + str(id))
                cur.execute("UPDATE ipv6 SET port_80=" + str(port80) + " WHERE id_ipv6 =" + str(id))
                db.commit()

            except Exception as e:
                sys.stderr.write("Error: " + str(e))
            except:
                db.rollback()
            lock.release()

            self.queue.task_done()


    def stop(self):
        self.keepRunning = False

And the checkPort method:

def checkPort(typ, address, port):
    if typ == "TCP":
        s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
    else:
        s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
    pom = 0 # 0/1 = True/False
    try:
        s.settimeout(2) # timeout 1.5 sekundy
        s.connect((str(address), port))
        s.settimeout(None)
        #time.sleep(0.5)
        pom = 1
        print str(address) + " >> on port: " + str(port) + " >> Connection was successfull"

    except socket.timeout:
        print str(address) + " >> on port: " + str(port) + " >> * Error: Timed out *"
    except socket.error as e:
        if e.errno == 10061:
            print str(address) + " >> on port: " + str(port) + " >> * No connection could be made - target machine refused it *"
    except Exception as ex:
        sys.stderr.write("Error: " + str(ex))

    return pom
  • 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-18T07:28:19+00:00Added an answer on June 18, 2026 at 7:28 am

    The following may help you along with your program. It is written for Python 3.x. I believe that the main problem is on the line args = self.queue.get() of your program. It should be fixed down below.

    import multiprocessing
    import queue
    import threading
    import sys
    import socket
    
    MAX_THREAD_COUNT = multiprocessing.cpu_count()
    
    def main(cur):
        cur.execute("""UPDATE ipv6
                          SET port_21 = 0,
                              port_80 = 0,
                              port_443 = 0
                        WHERE address = 'N/A'""")
        q = queue.Queue()
        for _ in range(MAX_THREAD_COUNT):
            CheckPort(q).start()
        cur.execute("""SELECT id_ipv6,
                              address
                         FROM ipv6
                        WHERE address != 'N/A'""")
        for row in cur.fetchall():
            q.put(row)
        q.join()
        for thread in threading.enumerate():
            if isinstance(thread, CheckPort):
                thread.stop()
                thread.join()
    
    class CheckPort(threading.Thread):
    
        def __init__(self, q):
            super().__init__()
            self.__q = q
            self.__run = True
    
        def stop(self):
            self.__run = False
    
        def run(self):
            while self.__run:
                try:
                    id, address = self.__q.get(True, 1)
                except queue.Empty:
                    continue
                with lock:
                    try:
                        cur.execute('''UPDATE ipv6
                                          SET port_21 = ?,
                                              port_80 = ?,
                                              port_443 = ?
                                        WHERE id_ipv6 = ?''',
                                    self.check_port(address, 21),
                                    self.check_port(address, 80),
                                    self.check_port(address, 443),
                                    id)
                        db.commit()
                    except Exception as error:
                        print('Error:', error, file=sys.stdout)
                    self.__q.task_done()
    
        @staticmethod
        def check_port(address, port):
            sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
            sock.settimeout(2)
            try:
                sock.connect((address, port))
            except socket.timeout:
                return 0
            else:
                sock.shutdown(socket.SHUT_RDWR)
                sock.close()
                return 1
    
    if __name__ == '__main__':
        try:
            main(cur)
        except Exception as error:
            print('Error:', error, file=sys.stdout)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with 2D transformation program I have the source code import
This is my server code I have a problem because my program freeze and
Problem: Have made a small mail program which works perfectly on my developer pc
I have a problem with my iPhone program. I have imported a folder into
Basically i have a problem with this timer program I am trying to put
with my RCP program I have the problem that I want to have more
I have this problem when trying to run hello world program using android SDK.
i have a problem. Some sql in my program could be written by the
I have a problem with debugging sessions. My program executes very well in a
I have a problem with Regular Expressions. I'm writing a small program that matches

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.