Skip to content

Commit c6e1e77

Browse files
committed
Multiprocessing Snippets
1 parent bbcbacc commit c6e1e77

34 files changed

+72
-0
lines changed
Lines changed: 2 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import concurrent.futures
2+
import time
3+
4+
start = time.perf_counter()
5+
6+
7+
def do_something(seconds):
8+
print(f'Sleeping {seconds} second(s)...')
9+
time.sleep(seconds)
10+
return f'Done Sleeping...{seconds}'
11+
12+
13+
with concurrent.futures.ProcessPoolExecutor() as executor:
14+
secs = [5, 4, 3, 2, 1]
15+
results = executor.map(do_something, secs)
16+
17+
# for result in results:
18+
# print(result)
19+
20+
finish = time.perf_counter()
21+
22+
print(f'Finished in {round(finish-start, 2)} second(s)')
20.1 MB
Loading
8.42 MB
Loading
3.3 MB
Loading
11.5 MB
Loading
2.92 MB
Loading
7.49 MB
Loading
12.3 MB
Loading

0 commit comments

Comments
 (0)