What is the concept of Multi threading. It would be better for me if anyone given answer in Python with example .

Last updated:6/15/2018 3:28:39 AM

1 Answers

Prakash nidhi Verma
Prakash nidhi Verma

Multi threading means multi processing and multitasking.You can speed your code up through multi-thread because python having multi threading packages. This happens very quickly so to the human eye it may seem like your threads are executing in parallel, but they are really just taking turns using the same CPU core.  

import threading 
 def print_cube(n):
    print('Cube: {}'.format(n*n*n))
def print_square(n):
    print('Square: {}'.format(n*n))
 if __name__ == '__main__':
    // creating thread
    t1 = threading.Thread(target=print_square, args=(10,))
    t2 = threading.Thread(target=print_cube, args=(10,))
    t1.start() // starting the thread 1
    t1.join() // exicute the thread 1

You can understand this by this image :

Happy Coding :)