Skip to content

Commit

Permalink
runners: Write some debug timing information to stderr after forking
Browse files Browse the repository at this point in the history
To aid in debugging weird timing issues after forking off a runner process,
write a couple of debug lines to stderr after forking, but before exec'ing, so
they will appear in the debug log files. This should otherwise be harmless as
all of the parsers either ignore the error output completely, or filter out the
lines they are interested in using regexes or prefix matching, and so will just
skip over these debug lines.

Signed-off-by: Toke Høiland-Jørgensen <[email protected]>
  • Loading branch information
tohojo committed Aug 9, 2023
1 parent 50ff542 commit 069a1e5
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions flent/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,20 +473,24 @@ def fork(self):
self.stdout.close()
self.stderr.close()
os.closerange(3, 65535)
pid = os.getpid()

try:
if self.start_event is not None:
os.write(2, f"{time.time()}: PID {pid} waiting for SIGUSR2\n".encode("utf-8"))
signal.signal(signal.SIGUSR2, self.handle_usr2)
self.start_event.wait()
signal.signal(signal.SIGUSR2, signal.SIG_DFL)

os.write(2, f"{time.time()}: PID {pid} sleeping for {self.delay} seconds\n".encode("utf-8"))
time.sleep(self.delay)
except:
os._exit(0)

env = dict(os.environ)
env.update(self._env)
prog = self.args[0]
os.write(2, f"{time.time()}: PID {pid} running execvpe({' '.join(self.args)})\n".encode("utf-8"))
os.execvpe(prog, self.args, env)
else:
self.debug("Forked %s as pid %d", self.args[0], pid)
Expand Down

0 comments on commit 069a1e5

Please sign in to comment.