Threads in Python

 import threading

import time

from concurrent.futures import ThreadPoolExecutor



def task(work):

    print(f"Task {work} running")

    time.sleep(1)

    

    

def sq(n):

    print(f"Square: {n*n}")

    time.sleep(1)


def cu(n):

    print(f"Cube: {n*n*n}")

    time.sleep(1)



# t3=threading.Thread(target=sq,args=(4,))

# t4=threading.Thread(target=cu,args=(4,))


# t3.start()

# t4.start()

# t3.join()

# t4.join()


with ThreadPoolExecutor(max_workers=2) as executor:

    executor.submit(task,1)

    executor.submit(task,2)


print("Done!!")

Comments

Popular posts from this blog

Requests and Urllib

Strings in C Language

Dictionary in Python