Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
robnagler committed Jan 18, 2025
1 parent 671353e commit 39f48cb
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions pykern/pksubprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,22 @@ def check_call_with_signals(cmd, output=None, env=None, msg=None, recursive_kill
all_pids = set()

def signal_handler(sig, frame):
pkdlog([sig, frame])
pkdlog([p, sig, frame])
try:
if p:
pkdlog("sent")
p.send_signal(sig)
else:
pkdlog("NOT sent")
except Exception as e:
pkdlog([e])
pass
finally:
ps = prev_signal[sig]
pkdlog([ps])
if ps in (None, signal.SIG_IGN, signal.SIG_DFL):
return
pkdlog("cascade")
ps(sig, frame)

def wait_pid():
Expand All @@ -73,6 +78,7 @@ def wait_pid():
all_pids.update(
(c.pid for c in z.children(recursive=True)),
)
pkdlog(all_pids)
x, s = os.waitpid(pid, os.WNOHANG)
if x != 0:
break
Expand All @@ -81,6 +87,7 @@ def wait_pid():
# process starts. Then polling less frequently
# helps avoid thrashing, especially with mpi.
t = 0.5
pkdlog([s])
return s

try:
Expand All @@ -89,6 +96,7 @@ def wait_pid():
stdout = open(output, "w")
stderr = subprocess.STDOUT if stdout else None
for sig in _SIGNALS:
pkdlog([sig, signal_handler])
signal.signal(sig, signal_handler)
p = subprocess.Popen(
cmd,
Expand All @@ -98,6 +106,7 @@ def wait_pid():
env=env,
)
pid = p.pid
msg = pkdlog
if msg:
msg("{}: started: {}", pid, cmd)
s = wait_pid()
Expand All @@ -112,8 +121,10 @@ def wait_pid():
raise
finally:
for sig in _SIGNALS:
pkdlog(["prev", sig, prev_signal[sig]])
signal.signal(sig, prev_signal[sig])
if not p is None:
pkdlog(["p", p])
if p is not None:
if msg:
msg("{}: terminating: {}", pid, cmd)
try:
Expand Down

0 comments on commit 39f48cb

Please sign in to comment.