View difference between Paste ID: PD7ndHz6 and FvgKqwi7
SHOW: | | - or go back to the newest paste.
1-
import time
1+
import time
2-
import sys
2+
import sys
3-
import signal
3+
import signal
4-
from subprocess import DEVNULL, PIPE, Popen
4+
from subprocess import DEVNULL, PIPE, Popen
5-
from functools import partial
5+
from functools import partial
6
7
8-
signal_value = int(sys.argv[1])
8+
signal_value = int(sys.argv[1])
9-
signal_value = signal.Signals(signal_value)
9+
signal_value = signal.Signals(signal_value)
10-
print("Using signal", signal_value)
10+
print("Using signal", signal_value)
11
12-
cmd = ["python", "guard.py", signal_value.name]
12+
cmd = ["python", "guard.py", signal_value.name]
13-
make_proc = partial(Popen, cmd)
13+
make_proc = partial(Popen, cmd)
14-
options = dict(stdout=DEVNULL, stderr=DEVNULL)
14+
options = dict(stdout=DEVNULL, stderr=DEVNULL)
15
16
17-
start = time.monotonic()
17+
start = time.monotonic()
18-
procs = [make_proc(**options) for _ in range(4)]
18+
procs = [make_proc(**options) for _ in range(4)]
19
20-
print("Waiting to finish")
20+
print("Waiting to finish")
21-
returncodes = set()
21+
returncodes = set()
22-
for proc in procs:
22+
for proc in procs:
23-
    returncodes.add(proc.wait())
23+
    returncodes.add(proc.wait())
24
25-
if len(returncodes) == 1 and returncodes.pop() == signal_value:
25+
if len(returncodes) == 1 and returncodes.pop() == signal_value:
26-
    print("All return codes are", signal_value)
26+
    print("All return codes are", signal_value)
27-
else:
27+
else:
28-
    print("Something went wrong.")
28+
    print("Something went wrong.")
29-
    print("Got following return codes", returncodes)
29+
    print("Got following return codes", returncodes)
30
31
32-
end = time.monotonic()
32+
end = time.monotonic()
33
34-
print(f"Starting, sending signal, waiting to finish took {end-start:.2f} seconds.")
34+
print(f"Starting, sending signal, waiting to finish took {end-start:.2f} seconds.")
35