print current thread in python 3
Question: I have this script:

    
    
    import threading, socket
    
    for x in range(800)
        send().start()
    
    class send(threading.Thread):
        def run(self):
            while True:
                try:
                    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                    s.connect(("www.google.it", 80))
                    s.send ("test")
                    print ("Request sent!")
                except:
                    pass
    

And at the place of "Request sent!" I would like to print something like:
"Request sent! %s" % (the current number of the thread sending the request)

What's the fastest way to do it?

**\--SOLVED--**

    
    
    import threading, socket
    
    for x in range(800)
        send(x+1).start()
    
    class send(threading.Thread):
        def __init__(self, counter):
            threading.Thread.__init__(self)
            self.counter = counter
        def run(self):
            while True:
                try:
                    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                    s.connect(("www.google.it", 80))
                    s.send ("test")
                    print ("Request sent! @", self.counter)
                except:
                    pass
    


Answer: You could pass your counting number (`x`, in this case), as a variable in your
send class. Keep in mind though that `x` will start at 0, not 1.

    
    
    for x in range(800)
        send(x+1).start()
    
    class send(threading.Thread):
        def __init__(self, count):
            self.count = count
    
        def run(self):
            while True:
                try:
                    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                    s.connect(("www.google.it", 80))
                    s.send ("test")
                    print ("Request sent!"), self.count
                except:
                    pass
    

Or, as Rob commented above in the other question,
[`threading.current_thread()`](http://docs.python.org/library/threading.html#threading.current_thread)
looks satisfactory.

