3131
3232from supervisor .socket_manager import SocketManager
3333
34+ from supervisor .rpcinterface import SupervisorNamespaceRPCInterface
35+ from supervisor .xmlrpc import (
36+ capped_int ,
37+ Faults ,
38+ RPCError ,
39+ )
40+
3441@functools .total_ordering
3542class Subprocess (object ):
3643
@@ -195,32 +202,6 @@ def spawn(self):
195202
196203 Return the process id. If the fork() call fails, return None.
197204 """
198- # this section is ownly triggered when using autostart -
199- # otherwise the dependencies are handled in the rpcinterface
200- # check if the process is dependent upon any other process and if so,
201- # make sure that one is in the RUNNING state
202- if self .config .depends_on is not None :
203- # keep track of RUNNING childs
204- running_childs = set ()
205- # wait/loop until all childs are running
206- while set (self .config .depends_on .keys ()) != running_childs :
207- for child in self .config .depends_on .values ():
208- if child .state is not ProcessStates .RUNNING :
209- # potentially remove child, if it is in running list
210- if child .config .name in running_childs :
211- running_childs .remove (child .config .name )
212- # check if it needs to be started
213- if child .state is not (ProcessStates .STARTING or ProcessStates .RUNNING ):
214- child .spawn ()
215- else :
216- child .transition ()
217- msg = ("waiting on dependee process {} to reach running state - currently in {}"
218- .format (child .config .name , getProcessStateDescription (child .state )))
219- self .config .options .logger .warn (msg )
220- else :
221- # child is running - add to set
222- running_childs .add (child .config .name )
223- time .sleep (0.5 )
224205
225206 options = self .config .options
226207 processname = as_string (self .config .name )
@@ -676,7 +657,7 @@ def __repr__(self):
676657 def get_state (self ):
677658 return self .state
678659
679- def transition (self ):
660+ def transition (self , supervisord_instance = None ):
680661 now = time .time ()
681662 state = self .state
682663
@@ -698,7 +679,14 @@ def transition(self):
698679 elif state == ProcessStates .STOPPED and not self .laststart :
699680 if self .config .autostart :
700681 # STOPPED -> STARTING
701- self .spawn ()
682+ # make sure dependent processes are spawned before
683+ # check if the process is dependent upon any other process and if so,
684+ # make sure that one is in the RUNNING state
685+ if self .config .depends_on is not None :
686+ rpc_interface = SupervisorNamespaceRPCInterface (supervisord_instance )
687+ rpc_interface .startProcess (self .group .config .name + ':' + self .config .name )
688+ else :
689+ self .spawn ()
702690 elif state == ProcessStates .BACKOFF :
703691 if self .backoff <= self .config .startretries :
704692 if now > self .delay :
@@ -865,9 +853,9 @@ def before_remove(self):
865853 pass
866854
867855class ProcessGroup (ProcessGroupBase ):
868- def transition (self ):
856+ def transition (self , supervisord_instance ):
869857 for proc in self .processes .values ():
870- proc .transition ()
858+ proc .transition (supervisord_instance )
871859
872860class FastCGIProcessGroup (ProcessGroup ):
873861
0 commit comments