-
Notifications
You must be signed in to change notification settings - Fork 10
/
subprocess-checker.py
36 lines (34 loc) · 1.2 KB
/
subprocess-checker.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 json
import math
import subprocess
import sys
import time
if __name__ == '__main__':
with open(sys.argv[1], 'r') as f:
websites = f.read().splitlines()
number_of_processes = int(sys.argv[2])
per_process = math.ceil(len(websites) / number_of_processes)
# split up the work based on number of processes
for i in range(number_of_processes):
sites = websites[i * per_process:(i + 1) * per_process]
with open("/tmp/list-{}.txt".format(i), 'w') as f:
f.write("\n".join(sites))
t0 = time.time()
processes = []
for i in range(number_of_processes):
p = subprocess.Popen(
["python3", "naive-checker.py", "/tmp/list-{}.txt".format(i)],
stdout=subprocess.PIPE)
processes.append(p)
# gather the results
combined = {}
for process in processes:
result = process.communicate()[0]
stats, _, _ = result.decode().split("\n")
for key, value in json.loads(stats).items():
if not combined.get(key):
combined[key] = 0
combined[key] += value
print(combined)
t1 = time.time()
print("getting website statuses took {0:.1f} seconds".format(t1-t0))