
# https://www.globalsino.com/ICs/page4853.html
# Use threading and its arguments to complete more tasks


from time import sleep, perf_counter
from threading import Thread


def new_task(id):
    print(f'\nStarting the new task {id}')
    sleep(1)
    print('\nThe new task is done')

start_time = perf_counter()

# Create 10 new threads and pass an id to each
threads = []
for n in range(1, 11):
    t = Thread(target=new_task, args=(n,))
    threads.append(t)
    t.start()

for t in threads:
    t.join()

end_time = perf_counter()

print(f'It took {end_time- start_time: 0.2f} second(s) to complete.')
