Skip to content

Commit 549c23a

Browse files
author
Michael Hammann
committed
feat: use set to keep track of processes that are already added to process queue
1 parent 8482b27 commit 549c23a

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

supervisor/process.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,13 @@ def spawn(self, supervisor=None):
203203
# make sure that one is in the RUNNING state
204204
# spawn if all dependees are running - else add to queue if not in queue already
205205
if self.config.depends_on is not None and any([dependee.state is not ProcessStates.RUNNING for dependee in self.config.depends_on.values()]):
206-
print('called spawn with dependency for process', self)
207206
# all dependees that are not in queue and not in STARTING need to be added to queue.
208207
for dependee in self.config.depends_on.values():
209208
if dependee.state is not (ProcessStates.STARTING or ProcessStates.RUNNING):
210-
if dependee not in supervisor.process_queue:
209+
if dependee.config.name not in supervisor.waiting_to_be_spawned:
211210
supervisor.process_queue.append(dependee)
211+
supervisor.waiting_to_be_spawned.add(dependee.config.name)
212212
else:
213-
print('called spawn')
214213
# if runningregex is used, set the log_offset correctly
215214
if self.config.runningregex is not None:
216215
try:

supervisor/rpcinterface.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,8 @@ def startProcess(self, name, wait=True):
330330

331331
process.spawn(self.supervisord)
332332

333+
#TODO make sure this process is properly spawned in the end and correctly handled now.
334+
333335
# We call reap() in order to more quickly obtain the side effects of
334336
# process.finish(), which reap() eventually ends up calling. This
335337
# might be the case if the spawn() was successful but then the process

supervisor/supervisord.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def __init__(self, options):
6060
self.process_groups = {}
6161
self.ticks = {}
6262
self.process_queue = deque()
63+
self.waiting_to_be_spawned = set()
6364

6465
def main(self):
6566
if not self.options.first:
@@ -274,18 +275,28 @@ def runforever(self):
274275
# spawn if all dependencies are running or process has no dependencies
275276
if self.process_queue[-1].config.depends_on is not None:
276277
if all([dependee.get_state() == ProcessStates.RUNNING for dependee in self.process_queue[-1].config.depends_on.values()]):
277-
self.process_queue.pop().spawn(self)
278+
ready_process = self.process_queue.pop()
279+
ready_process.spawn(self)
280+
try:
281+
self.waiting_to_be_spawned.remove(ready_process.config.name)
282+
except KeyError:
283+
pass
278284
# add any dependee which is not RUNNING or STARTING to queue
279285
else:
280286
for dependee in self.process_queue[-1].config.depends_on.values():
281-
#print('dependee is: ', dependee, dependee.state, dependee.state == ProcessStates.STOPPED)
282287
if dependee.state is not (ProcessStates.STARTING or ProcessStates.RUNNING):
283288
# Should we check if the process is already in the queue?
284-
self.process_queue.append(dependee)
289+
if dependee.config.name not in self.waiting_to_be_spawned:
290+
self.process_queue.append(dependee)
291+
self.waiting_to_be_spawned.add(dependee.config.name)
285292

286293
else:
287-
print('spawning something with no dependency!')
288-
self.process_queue.pop().spawn(self)
294+
ready_process = self.process_queue.pop()
295+
ready_process.spawn(self)
296+
try:
297+
self.waiting_to_be_spawned.remove(ready_process.config.name)
298+
except KeyError:
299+
pass
289300

290301
self.reap()
291302
self.handle_signal()

0 commit comments

Comments
 (0)