Skip to content

Commit d2e0e60

Browse files
committed
Threading\S06-Thread-Pool-Executor-concurrent-futures-module\S06-01-ThreadPoolExecutor
1 parent 86e2e2e commit d2e0e60

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from concurrent.futures import ThreadPoolExecutor
2+
import time
3+
4+
5+
start = time.perf_counter()
6+
7+
def some_task(name, delay):
8+
print(f"Thread {name} Started.")
9+
time.sleep(delay)
10+
print(f"Thread {name} Finished.")
11+
12+
13+
names = ["One", "Two", "Three", "Four"]
14+
delay = [3, 3, 3, 3]
15+
16+
with ThreadPoolExecutor(max_workers=2) as executor:
17+
executor.map(some_task, names, delay)
18+
19+
20+
end = time.perf_counter()
21+
exe_time = end - start
22+
print(f"Execution Time: {exe_time} sec")

0 commit comments

Comments
 (0)