-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultithread.py
More file actions
40 lines (29 loc) · 725 Bytes
/
multithread.py
File metadata and controls
40 lines (29 loc) · 725 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# -*- coding: utf-8 -*-
"""Multithread.ipynb
Automatically generated by Colab.
Original file is located at
https://colab.research.google.com/drive/1hHqlzDZJBL9AXM1lELEIVrhikTzgY4Yk
"""
import time
import threading
def square(num_list):
for n in numList:
time.sleep(0.3)
print("square",n*n)
def cube(num_list):
for n in numList:
time.sleep(0.3)
print("cube",n*n*n)
numList = [1,2,3,4,5,6]
t=time.time()
square(numList)
cube(numList)
print("job finished...(No threading)",time.time()-t)
t=time.time()
t1=threading.Thread(target=square,args=(numList,))
t2=threading.Thread(target=cube,args=(numList,))
t1.start()
t2.start()
t1.join()
t2.join()
print("job finished...(threading)",time.time()-t)