Python Thread - start() method

Start a thread in python by creating a thread object and invoking the start method on it.

Thread Updated 20 Sep 2016 1 min read

Method Name

start()

Method Overview

The method starts a Python thread. A thread is started after some fractional delta time after the start() call is made, 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 on a thread Python raises a RunTimeError.

Example

python
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

Output
10 Random numbers between and 100

17

78

90

7

63

27

57

98

27

9