Friday, March 27, 2020

threading example in python

from threading import *
import time
e=Event()
def consumer():
    print("consumer thread is waiting for updation")

    e.wait()
    print("consumer got notification and consuming items")

def producer():
    time.sleep(5)
    print("producer thread is producing items")
    print("producer thread giving notification by setting  event")
    e.set()
   
t1=Thread(target=producer)
t2=Thread(target=consumer)
t1.start()
t2.start()

output:
consumer thread is waiting for updation
producer thread is producing items
producer thread giving notification by setting  event
consumer got notification and consuming items

No comments:

Post a Comment

python class topic video