1
0
Fork 0

Keeping track of children

This commit is contained in:
Gregory Eremin 2015-02-12 03:04:56 +07:00
parent e21d18d359
commit f01ebc27cf
2 changed files with 11 additions and 4 deletions

View File

@ -23,10 +23,7 @@ func NewApp() *App {
a := &App{
config: conf,
chains: chain.NewBank(conf.C().ChainsConfig, ub),
sv: &Supervisor{
Bin: conf.C().Python.BinPath,
Wrapper: conf.C().Python.WrapperPath,
},
sv: NewSupervisor(conf.C().Python.BinPath, conf.C().Python.WrapperPath),
}
a.chains.Reload()

View File

@ -11,9 +11,18 @@ type (
Supervisor struct {
Bin string
Wrapper string
procs map[string]*exec.Cmd
}
)
func NewSupervisor(bin, wrapper string) *Supervisor {
return &Supervisor{
Bin: bin,
Wrapper: wrapper,
procs: map[string]*exec.Cmd{},
}
}
// XXX: We're about to spawn hundreds of Python processes
func (s *Supervisor) Start(units ...string) {
for _, name := range units {
@ -24,6 +33,7 @@ func (s *Supervisor) Start(units ...string) {
if err := cmd.Start(); err != nil {
log.Printf("Failed to start unit: %s (%s)", name, err.Error())
}
s.procs[name] = cmd
time.Sleep(200 * time.Millisecond) // Don't spawn processes too fast
}