I am trying to continuously through time from client side to server side even if server is not accepting the connection I have written following function on client side
def run(self):
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
Now I am inside another class its name is loginGui, and i want to execute above global function run with the help of the a thread so that client continuously throws the time to server side while my rest of client code executes. So i wrote following code inside a class loginGui
class loginGui:
def run_client(self):
thread.start_new_thread(run,())
when I call the above function run_client(), thread runs but for some reasons it comes out of the loop and stops throwing the time so I tried this another approach..
class FuncThread(threading.Thread):
def __init__(self, target, *args):
self._target = target
self._args = args
threading.Thread.__init__(self)
def run(self):
self._target(*self._args)
I wrote above class and then in run_client() function I did following changes..
def run_client(self):
t1 = FuncThread(run,())
t1.start()
t1.join()
Now when I call run_client() it creates a thread and calls the global function run() but now the problem is it get struck in the while loop and keep throwing the time.
conclusion: What I basically want is to create a thread which call my function run and keep throwing the time without getting struck in while loop..