ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel()
ctx, cancel := cmdutil.ContextWithInterrupt(context.Background()) defer cancel() go func() { // long running process }() select { case <-ctx.Done(): // handle graceful shutdown }The go github.com.juju.cmd Context package is a package library.