Trying to familiarize myself with subroutines and Go overall, and I'm trying to write a script that will basically start up all the services of my django app with sync.WaitGroup
and keep them running until i manually kill the Go script, which is why i'm not having the intitialize()
function actually tell the waitgroup that the processes are finished. Getting the dreaded fatal error: all goroutines are asleep - deadlock!
message.
func main() {
var wg sync.WaitGroup
os.Chdir("/home/Projects/djangoapp")
cc := []cmds{cmds{
name: "django",
cmdsl: []string{"/home/Projects/djangoapp/env/bin/python", "manage.py", "runserver"},
},
cmds{
name: "celeryd",
cmdsl: []string{"/home/Projects/djangoapp/env/bin/celery", "-A", "djangoapp", "worker", "-l", "INFO", "-S", "django"},
},
}
for x := 0; x < 2; x++ {
wg.Add(1)
fmt.Println("starting up", cc[x].name)
go initialize(cc[x])
}
wg.Wait()
}
func initialize(ccmds cmds) {
cmd := exec.Command(ccmds.cmdsl[0], ccmds.cmdsl[1:]...)
cmd.Env = append(os.Environ(), "DJANGO_SETTINGS_MODULE=articleadmin.settings.default")
fmt.Println("initializing", ccmds.name)
cmd.Start()
fmt.Println("started", ccmds.name)
cmd.Wait()
}
It starts up the services, but then barfs with the deadlock error. What am I doing wrong?