-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmulticrunch.py
38 lines (30 loc) · 1.13 KB
/
multicrunch.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
37
38
import subprocess
import time
from random import randint
NUM_PROCESSES = 6
# Define commands
commands = [f"forge test --mt testVanity --fuzz-seed {randint(0, 2 ** 32)}" for _ in range(NUM_PROCESSES)]
if __name__ == "__main__":
# Build
proc = subprocess.Popen("forge build", stdout=subprocess.PIPE)
proc.wait()
print(proc.communicate()[0].decode())
# Start the processes
processes = [subprocess.Popen(cmd, stdout=subprocess.PIPE) for cmd in commands]
# Monitor the processes
while True:
for proc in processes:
# Check if process has finished
if proc.poll() is not None:
# Get the output
result = proc.communicate()[0].decode()
print(result)
# Write the result to file
with open('vanity.txt', 'w') as file:
file.write(result)
# Kill the rest
for p in processes:
if p != proc:
p.kill()
exit(0)
time.sleep(0.1) # sleep for 100 ms to reduce CPU usage