User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 456,549 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,369 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Python advertiser: Programming Forums
Views: 1015 | Replies: 4 | Solved
Reply
Join Date: Oct 2006
Posts: 19
Reputation: MarkWalker84 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
MarkWalker84 MarkWalker84 is offline Offline
Newbie Poster

Thread / Timers / Pinging... Help :-s

  #1  
Jan 23rd, 2007
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:
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2006
Posts: 19
Reputation: MarkWalker84 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
MarkWalker84 MarkWalker84 is offline Offline
Newbie Poster

Re: Thread / Timers / Pinging... Help :-s

  #2  
Jan 24th, 2007
Problem solved :-)
Reply With Quote  
Join Date: Jul 2005
Location: France
Posts: 1,051
Reputation: bumsfeld is an unknown quantity at this point 
Rep Power: 6
Solved Threads: 46
bumsfeld's Avatar
bumsfeld bumsfeld is offline Offline
Veteran Poster

Re: Thread / Timers / Pinging... Help :-s

  #3  
Jan 24th, 2007
Any hints on how you solved it?
Reply With Quote  
Join Date: Oct 2006
Posts: 19
Reputation: MarkWalker84 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
MarkWalker84 MarkWalker84 is offline Offline
Newbie Poster

Re: Thread / Timers / Pinging... Help :-s

  #4  
Jan 25th, 2007
sure...

  1. import thread
  2. import time
  3.  
  4. def RunPing(self):
  5. while 1:
  6. time.sleep(5)
  7. print "PING!"
  8.  
  9. 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...

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

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


Mark
Last edited by MarkWalker84 : Jan 25th, 2007 at 6:45 am.
Reply With Quote  
Join Date: Jul 2005
Location: France
Posts: 1,051
Reputation: bumsfeld is an unknown quantity at this point 
Rep Power: 6
Solved Threads: 46
bumsfeld's Avatar
bumsfeld bumsfeld is offline Offline
Veteran Poster

Re: Thread / Timers / Pinging... Help :-s

  #5  
Jan 25th, 2007
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Python Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Python Forum

All times are GMT -4. The time now is 5:11 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC