Open Alsan opened 1 year ago
I'm trying to write a program to auto tag my collections. It'll call the tmsu through shell execution, then combining fd to loop through all files in my collections. It worked as expected, except the tmsu returns database locked error occasionally.
tmsu
fd
Here's my program fragment:
func runCommand(filename string, command string, ch chan output) { // fmt.Println(cmd) fields := strings.Fields(command) cmd := exec.Command(fields[0], fields[1:]...) out, err := cmd.CombinedOutput() ch <- output{out, err} } ... ch := make(chan output) go runCommand(fn, cmd, ch) select { case <-time.After(2 * time.Second): errs.PrintToStdErrAndExit(fmt.Sprintf("timeout: %s", cmd)) case x := <-ch: if x.err != nil { errs.PrintToStdErrAndExit(fmt.Sprintf("error: %s", string(x.out))) } else { fmt.Println(fn) } }
Any suggestion on optimizing the program?
I'm trying to write a program to auto tag my collections. It'll call the
tmsu
through shell execution, then combiningfd
to loop through all files in my collections. It worked as expected, except the tmsu returns database locked error occasionally.Here's my program fragment:
Any suggestion on optimizing the program?