Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bin/generate_prim_file: use POSIX process groups instead of psutil #717

Merged
merged 3 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions bin/generate_prim_file
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import atexit
import time
from datetime import datetime
import fcntl
import psutil


def readline_nonblocking(output):
Expand Down Expand Up @@ -102,7 +101,8 @@ finished = False
# run simulation
print(' '.join(sim_cmd))
p = subprocess.Popen(args=sim_cmd, env=dawn_env,
stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE,
preexec_fn=os.setsid)
__child_pid = p.pid
while elapse.seconds < args.timeout:
line = readline_nonblocking(p.stdout)
Expand Down Expand Up @@ -134,14 +134,10 @@ while elapse.seconds < args.timeout:

time.sleep(1)

p.kill()
# use to kill the subprocess generated from the python wrapper
# this is unsafe so maybe more checks required
for proc in psutil.process_iter():
pinfo = proc.as_dict(attrs=['pid', 'name', 'create_time'])
if pinfo['pid'] == p.pid + 1 and pinfo['name'] == 'python':
print('kill {}, generated from {}'.format(pinfo, p.pid))
os.kill(pinfo['pid'], signal.SIGTERM)
try:
os.killpg(os.getpgid(p.pid), signal.SIGTERM)
except ProcessLookupError:
pass # assume process is dead

# revert the change
#os.system('sed -i \'s/radius=\"EcalEndcapP_FiberRadius*10\"/radius=\"EcalEndcapP_FiberRadius\"/\' {}'.format(ci_ecal))
Expand Down
2 changes: 1 addition & 1 deletion src/BarrelCalorimeterScFi_geo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ void buildFibers(Detector& desc, SensitiveDetector& sens, Volume& s_vol, int lay
struct Fiber {
Point pos;
bool assigned = false;
Fiber(const Point& p) : pos(p){};
Fiber(const Point& p) : pos(p) {};
};
std::vector<Fiber> fibers(f_pos.begin(), f_pos.end());

Expand Down