3.1 CreatingAThread.pdf
(
618 KB
)
Pobierz
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
Plik z chomika:
kendzior21
Inne pliki z tego folderu:
1. Section Introduction.mp4
(27630 KB)
7. IPC using Conditions.mp4
(40205 KB)
4. Mutex.mp4
(32678 KB)
5. Semaphore.mp4
(22310 KB)
2.1 IntroMultithreading.pdf
(1554 KB)
Inne foldery tego chomika:
01. Introduction to Python
02. Python Installation and Setup
03. Python Datatypes
04. Operators and Expression
05. Conditional Statements
Zgłoś jeśli
naruszono regulamin