with this sort of thing.
You need to run it from terminal or somewhere and insert a SIGINT.
The SIGINT catcher somehow did the 10 second sleep, shouldn't they get killed instead?
Your main function doesn't end right away. It sleeps for an hour. So sigint would sleep for 10 seconds and then exit
time.Sleep(time.Hour) Due to this line
I see then. So how would one lock a program into waiting for cleanup to finish when interupt is called? For example, something like panic: defer func(){ if recov...... }()
sigint := make(chan os.Signal) signal.Notify(sigint, os.Interrupt) fmt.Println("Run your code...") <-sigint fmt.Println("clean up and exit")
Wouldn't it be better if you did that using Signal/Broadcast?
I told you not to use os.Exit
Обсуждают сегодня