Ecco un esempio semplice
codice:
import threading import time # Define a function to be threaded def print_time( threadName, delay): count = 0 while count < 5: # Wait(delay * 1000) time.sleep(delay) count += 1 Misc.SendMessage ("%s: %s" % ( threadName, time.ctime(time.time()) )) # Create two threads as follows try: t1 = threading.Thread(target=print_time, args=("Thread-1", 0.005 )) t1.start() t2 = threading.Thread(target=print_time, args=("Thread-2", 1 )) t2.start() except: Misc.SendMessage ("Error: unable to start thread")
Lascia un commento: