Python thread restart
Question: I have a thread when it is run it has an infinite loop. When another thread is
stopped, I wish to reset all the threads again, There threads have sockets
that transfer data between each other. I am using

    
    
    node1._Thread__stop()
    

function to stop the thread runing, but when I try to create a new thread with
the same name:

    
    
    node1 = node.node(8081,8082,token,1,"Node A",0)
    node1.start()
    

It gives out an error

    
    
    [Errno 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted.
    

I am not sure if the stop function worked on the threads, because I have a
timeout clause for a socket that if it doesn't receive anything to print
timeout. This prints after the error occured.

What would be a better reset of a thread/socket


Answer: I'm not sure about what are you looking for. However, I recommend you to have
a look at this [answer](http://stackoverflow.com/a/325528/183066) to a related
question.

The important point is that isn't a good idea to terminate a thread when it's
holding a resource such as a socket as in your case. The right way to do it
would be to use any of the synchronization mechanisms (the answer referenced
above uses an example with `threading.Event`, but it could be, for example, a
`threading.Condition` if it suits your needs better) available to release the
resource or, as it seems you need, reset some internal data to start from
scratch.

I hope this helps.

