How to launch a function at regular time intervals ?

David davigier at googlemail.com
Fri Aug 14 18:28:06 EDT 2009


With your help, Franck, I think I finally got it to work. This is how
I did it:

# In the main program, launch the 2 threads CStoreData and
CTransferData, which will run indefinitely until they are stopped (if
the threads were launched inside the while loop, there would be an
infinitely growing number of threads CStoreData all doing the same
thing, same for CTransferData)

func_store_data = CStoreData()
func_store_data.start()

func_transfer_data = CTransferData()
func_transfer_data.start()

# While loop, just to keep the threads running until they are stopped
at the end of the program. If there wasn't a while loop, the threads
would be stopped right after they are launched. The while loop
separates the "start" of the threads from the "stop" of the threads

while 1
  if end_condition:  # terminate program
            break  # break out of while loop

# Stop all running threads at end

func_store_data.stop()
func_store_data.join()

func_transfer_data.stop()
func_transfer_data.join()


Again thanks a lot to all of you for your precious help.

David



More information about the Python-list mailing list