Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > stop thread from outside 'run'

Reply
Thread Tools

stop thread from outside 'run'

 
 
Prashant
Guest
Posts: n/a
 
      06-05-2012
Hi,

I am using tornado web socket server to communicate between python(server) and browser(client). To mimic the behavior of sending data to client and get results back, I am using threaded approach:

class JobThread(threading.Thread):
""""""
def __init__(self, target):
""""""
super(JobThread, self).__init__()
self.target = target
self.res = None
self.stoprequest = threading.Event()
self.start()
self.join()
# Execution stops here and wait
return self.result()

def run(self):
""" Start this thread """
self.target()
while not self.stoprequest.isSet():
print "running..."

def result(self):
""""""
return self.res

def kill(self, result):
""" Kill this thread """
self.res = result
self.stoprequest.set()

def ReceiveData(message):
""""""
global t
print str(message)
t.kill(message)

def SendData(data_string):
""""""
sendMessageWS(data_string)

result = JobThread(partial(SendData, data_string))

As soon as jobThread instance starts it sends data to websocket and wait for client to response. Client is sending back results but 'ReceiveData' is not getting called because of infinite loop in 'run' method. The only way you can stop the thread is from outside when "ReceiveData" executes and kill the threaded instance 't'.

Any pointers?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
help with pix inside->outside + dmz->outside + inside->outside->dmz Jack Cisco 0 09-19-2007 01:57 AM
CallForward outside->inside->outside failed after one ring. Yogz Cisco 1 04-16-2007 03:58 PM
Thread.stop makes thread unabled to be signalled Benji Java 34 10-28-2005 09:02 AM
nat from outside to outside dt1649651@yahoo.com Cisco 1 08-21-2005 04:26 PM
How to stop a thread without using stop() Son KwonNam Java 11 04-09-2004 08:01 PM



Advertisments