Hi everyone!

Im stuck...

I'm currently writing a GUI program to control a piece of machinery. I am using wxPython along with a few other bits and bobs including USPP for serial access.

My problem is that i need some way of 'pinging' the machine. ie I want to be able to regularly send an 'are you still there' message to the on board hardware, receive a simple yes or no and not really know it has done anything (must not interrupt the usability of the program)

Ive done some searching and i think threads must be the answer here but that is totally new territory for me...


Any help would be greatly appreciated :-)

Thanks,


Mark :mrgreen:

sure...

import thread
import time
 
def RunPing(self):
while 1:
time.sleep(5)
print "PING!"
 
thread.start_new_thread(RunPing,())

clearly there will be a little more to it in the end... lol, but that seems to do the trick.

Starts a new thread that repeats an action every 'x' seconds. The rest of the progam can continue as normal. Jobs-a-goodun :-)

One thing to note is that its a good idea to close the thread when the program exits...

def OnClose(self, event):
    thread.exit()

Not sure how it would work with more than 1 thread but 1 is all i need :-)


Mark

This question has already been answered. Start a new discussion instead.