-
Notifications
You must be signed in to change notification settings - Fork 3
/
utils.py
36 lines (20 loc) · 797 Bytes
/
utils.py
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
import concurrent.futures
import multiprocessing
import uuid
from database import insert_row
def insert_rows_in_parallel(args_list):
num_procs = len(args_list)
print(f"Spawning {num_procs} processes...")
pool = multiprocessing.Pool(num_procs)
results = pool.map(insert_row, args_list)
pool.close()
pool.join()
print(f"{num_procs} processes complete.")
def insert_rows_in_parallel_cf(args_list):
num_procs = len(args_list)
print(f"Spawning {num_procs} processes...")
with concurrent.futures.ProcessPoolExecutor(max_workers=num_procs) as executor:
executor.map(insert_row, args_list)
print(f"{num_procs} processes complete.")
def generate_example_rows(num_records):
return [(str(uuid.uuid4()),) for _ in range(0, num_records)]