Q:

Python Program to illustrate parameterized threads

belongs to collection: Python Threading Programs

0

Python uses the threading library to support multithreading and some more functions. We can pass arguments while creating the thread which can then be used when the thread is running.

The passed parameters can be accessed using the array param[] that stores it.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Python program to illustrate parameterized threads

import threading
import time

def ProcessOne(*param):
    while(True):
        print(param[0],threading.current_thread().getName(),"is Running",param[1])
        time.sleep(param[2])

def ProcessTwo(*param):
    while(True):
        print(param[0],threading.current_thread().getName(),"is Running",param[1])
        time.sleep(param[2])

T1=threading.Thread(target=ProcessOne,name="Swift",args=('Maruti',200,1))
T2=threading.Thread(target=ProcessTwo,name='I20',args=('Hyundai',220,5))

T1.start()
T2.start()

Output:

Maruti Swift is Running 200
Hyundai I20 is Running 220
Maruti Swift is Running 200
Maruti Swift is Running 200
Maruti Swift is Running 200
Maruti Swift is Running 200
Hyundai I20 is Running 220
Maruti Swift is Running 200
Maruti Swift is Running 200
Maruti Swift is Running 200
Maruti Swift is Running 200
Maruti Swift is Running 200
Hyundai I20 is Running 220
...
...

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Python program to illustrate multithreading... >>
<< Python program to illustrate naming of threads...