forked from DiamondLightSource/fast-feedback-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipetest.py
46 lines (36 loc) · 1.34 KB
/
pipetest.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
39
40
41
42
43
44
45
46
import os
import subprocess
def run_executable(executable_path, data_filepath, num_threads, num_images):
# Create a pipe to capture the output
read_fd, write_fd = os.pipe()
print("Pipe FDs:", read_fd, write_fd)
# Command to run the executable
command = [
"--sample",
data_filepath,
"--images",
str(num_images),
"--threads",
str(num_threads),
"--pipe_fd",
str(write_fd),
]
# Run the executable
print("Running:", " ".join(command))
process = subprocess.Popen(command, executable=executable_path, pass_fds=[write_fd])
# Read from the pipe
with os.fdopen(read_fd, "r") as pipe_in_file:
for line in pipe_in_file:
# Process each line of JSON output
if line.strip() == "EOF":
print("End of output")
break # Exit the loop when "EOF" is received
print("Received:", line.strip())
# Wait for the process to finish
process.wait()
if __name__ == "__main__":
executable_path = "../build/spotfinder"
data_filepath = "/dls/mx-scratch/gw56/i04-1-ins-huge/Insulin_6/Insulin_6_1.nxs"
num_threads = 40 # Set the number of threads as needed
num_images = 40 # Set the number of images as needed
run_executable(executable_path, data_filepath, num_threads, num_images)