I have following code which compares user input
import thread,sys
if(username.get_text() == 'xyz' and password.get_text()== '123' ):
thread.start_new_thread(run,())
def run():
print "running client"
start = datetime.now().second
while True:
try:
host ='localhost'
port = 5010
time = abs(datetime.now().second-start)
time = str(time)
print time
client = socket.socket()
client.connect((host,port))
client.send(time)
except socket.error:
pass
If I just call the function run() it works but when I try to create a thread to run this function, for some reason the thread is not created and run() function is not executed I am unable to find any error..
Thanks in advance…
you really should use the
threadingmodule instead ofthread.what else are you doing? if you create a thread like this, then the interpreter will exit no matter if the thread is still running or not
for example:
–> this produces:
where as:
works as expected. if you don’t want to keep the interpreter waiting for the thread, just set daemon=True* on the generated Thread.
*edit: added that in example