Python Exception in Thread

Master Python with 70+ Hands-on Projects and Get Job-ready - Learn Python

Program 1

import time
from threading import *
#Exception in Thread
# def display(a,b):
#     print("This is my display Thread")
#     c=a//b  # threading.excepthook()

# # Main Thread
# T1=Thread(target=display,args=(20,5))
# T1.start()
# a=int(input("Enter First Number"))
# b=int(input("Enter First Number"))
# c=a//b   # sys.excepthook()
# print(c)
# c=a+b
# print(c)
# c=a-b
# print(c)
def display():
    try:
        print("This is my display Thread")
        print(15//0) 
    except Exception as obj:
        print("Unable to divide by zero")    

def show(n):
    print("This is my show Thread")
    for i in range(1,11):
        print(n*i)
        time.sleep(1)

#Main Thread
T1=Thread(target=display)
T2=Thread(target=show, args=(8,))
T1.start()
T2.start()

 

Did you like our efforts? If Yes, please give DataFlair 5 Stars on Google

courses

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *