Method Name:
start()
Method Overview:
Starts a python thread.
A thread is started after some fractional delta time, as the thread needs to be initialised
before it is executed in the operating system context.
Exceptions:
When start() method is called more than once, will raise a RunTimeError.
If required, create another instance of the child thread again start that thread.
Example:
import random from threading import Thread
# A function that generates count times random numbers between 1 to 100 # This function will be run as a child thread def RandomNumberGenerator(Count): print("%d Random numbers between and 100"%(Count)) for i in range(0,Count): print(random.randint(1, 100))
#Create Random Number Generator Thread RandomNumberThread = Thread(target=RandomNumberGenerator(10))
#Start the Random Number Thread RandomNumberThread.start()
RandomNumberThread.join() |
Output:
myMac:PythonExamples macuser$ python StartExample.py 10 Random numbers between and 100 17 78 90 7 63 27 57 98 27 9 |