0% found this document useful (0 votes)
2 views

CreatingAThread

The document explains two methods for creating a thread in Python: using a function and using a class. It details how to implement threading by importing the threading module, starting a thread, and managing execution with sleep for slower output. Additionally, it notes that the output may vary due to simultaneous execution of threads.

Uploaded by

panwar14
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

CreatingAThread

The document explains two methods for creating a thread in Python: using a function and using a class. It details how to implement threading by importing the threading module, starting a thread, and managing execution with sleep for slower output. Additionally, it notes that the output may vary due to simultaneous execution of threads.

Uploaded by

panwar14
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Creating a thread

There are two ways to create a thread.


1. Using function( method )
2. Using a class.

Using function

• Suppose we want to print numbers that are 65 , 66 ……90 . This numbers


are ascii code of alphabets. We use for loop for this

for i in range(65,69):

print ( i )

• Now we will create a thread for this we have to import threading module

• It will create a thread using the function display to run we use t.start()

First create a thread

then start a thread

• t.join() it will wait for the main program


• Two thread run simultaneously it will give the mixed thread ( Alphabets and
numbers )

• The output will not get same always

• If you want them to execute slowly. Then you can import time and use
sleep

• It will slow down the program

sleep( )

With class

• In this we don’t have to create objects of the thread

You might also like