Skip to content

Commit

Permalink
fix crash on sr3c pidfiles (i01.pid)
Browse files Browse the repository at this point in the history
  • Loading branch information
reidsunderland committed Sep 24, 2024
1 parent e90cd76 commit b45bf25
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions sarracenia/sr.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,9 @@ def _read_state_dir(self):
continue

if pathname[-4:] == '.pid':
i = int(pathname[0:-4].split('_')[-1])
i = self._instance_num_from_pidfile(pathname, c, cfg)
if i < 0:
continue
if t.isdigit():
#print( "pid assignment: {c}/{cfg} instance: {i}, pid: {t}" )
self.states[c][cfg]['instance_pids'][i] = int(t)
Expand Down Expand Up @@ -585,7 +587,9 @@ def _find_missing_instances_dir(self, dir):
for filename in os.listdir():
# look at pid files, find ones where process is missing.
if filename[-4:] == '.pid':
i = int(filename[0:-4].split('_')[-1])
i = self._instance_num_from_pidfile(filename, c, cfg)
if i < 0:
continue
if i != 0:
p = pathlib.Path(filename)
if sys.version_info[0] > 3 or sys.version_info[
Expand Down Expand Up @@ -3023,6 +3027,19 @@ def _post_can_be_daemon(self, component, config):
return (component in ['post', 'cpost'] and self.configs[component][config]['options'].sleep > 0.1 and
hasattr(self.configs[component][config]['options'], 'path'))

def _instance_num_from_pidfile(self, pathname, component, cfg):
if os.sep in pathname:
pathname = pathname.split(os.sep)[-1]
if '_' in pathname:
i = int(pathname[0:-4].split('_')[-1])
# sr3c components just use iXX.pid
elif component[0] == 'c':
i = int(pathname[0:-4].replace('i', ''))
else:
logger.error(f"Failed to determine instance # for {component}/{cfg} {pathname}")
i = -1
return i


def main():
""" Main thread for sr dealing with parsing and action switch
Expand Down

0 comments on commit b45bf25

Please sign in to comment.