Skip to content

Commit 2c4e13c

Browse files
author
Michael Hammann
committed
fix: restructure depends_on flag. No using dicts to store dependent processes and only start process if all dependent processes are in RUNNING state
1 parent ba25802 commit 2c4e13c

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

supervisor/process.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,6 @@ def spawn(self):
195195
196196
Return the process id. If the fork() call fails, return None.
197197
"""
198-
# check if the process is dependent upon any other process and if so make sure that one is in the RUNNING state
199-
if self.config.depends_on is not None:
200-
for process in enumerate(self.config.depends_on):
201-
if self.config.depends_on[process[0]].state not in RUNNING_STATES:
202-
self.config.depends_on[process[0]].spawn()
203-
204198
options = self.config.options
205199
processname = as_string(self.config.name)
206200

supervisor/rpcinterface.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,31 @@ def startProcess(self, name, wait=True):
281281
@return boolean result Always true unless error
282282
283283
"""
284+
# check if the process is dependent upon any other process and if so make sure that one is in the RUNNING state
285+
group, process = self._getGroupAndProcess(name)
286+
if process.config.depends_on is not None:
287+
# keep track of RUNNING childs
288+
running_childs = set()
289+
# wait/loop until all childs are running
290+
while set(process.config.depends_on.keys()) != running_childs:
291+
for child in process.config.depends_on.values():
292+
if child.get_state() != ProcessStates.RUNNING:
293+
# potentially remove child, if it is in running list
294+
if child.config.name in running_childs:
295+
running_childs.remove(child.config.name)
296+
# check if it needs to be started
297+
if child.state is not (ProcessStates.STARTING or ProcessStates.RUNNING):
298+
self.startProcess(child.config.name)
299+
else:
300+
child.transition()
301+
msg = ("waiting on dependee process {} to reach running state - currently in {}"
302+
.format(child.config.name, getProcessStateDescription(child.state)))
303+
self.supervisord.options.logger.warn(msg)
304+
else:
305+
# child is running - add to set
306+
running_childs.add(child.config.name)
307+
time.sleep(0.5)
308+
284309
self._update('startProcess')
285310
group, process = self._getGroupAndProcess(name)
286311
if process is None:

supervisor/supervisord.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def run(self):
9292
# check dependencies for all programs in group:
9393
for conf in enumerate(config.process_configs):
9494
if config.process_configs[conf[0]].depends_on is not None:
95-
processes=[]
95+
process_dict=dict({})
9696
# split to get all processes in case there are multiple dependencies
9797
dependent_processes = (config.process_configs[conf[0]].depends_on).split()
9898
for process in dependent_processes:
@@ -102,8 +102,8 @@ def run(self):
102102
except:
103103
dependent_group=dependent_process=process
104104
g.addEdge(config.process_configs[conf[0]].name, dependent_process)
105-
processes.append(self.process_groups[dependent_group].processes[dependent_process])
106-
config.process_configs[conf[0]].depends_on = processes
105+
process_dict[dependent_process] = self.process_groups[dependent_group].processes[dependent_process]
106+
config.process_configs[conf[0]].depends_on = process_dict
107107
# check for cyclical process dependencies
108108
if g.cyclic() == 1:
109109
raise AttributeError('Process config contains dependeny cycle(s)! Check config files again!')

0 commit comments

Comments
 (0)