Total Post:113


 483  View(s)
Rate this:

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

  1. Re: Multithreading

    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 :)


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.