It queues your Python signal handling function, returns from the signal handler, and then runs it on the main loop at the next tick.
As far as I know this works fine. I wrote the same program in Python and it seems to work just fine, and have more functionality than the Go version. I guess one problem is that if you do a long blocking syscall on a tick in the main loop, your signal handler can be delayed indefinitely. There might be some hacks around this in the Python interpreter, but I don't recall offhand.
Though it is definitely a killer feature of Go to write in a blocking style rather than in a state machine style... but I feel that there might have been a way to do it without baking it so hard into the runtime (?). Maybe like coroutines in Python, which run on a single thread and are optional.
M:N threading causes a lot of other complications too, like calling from C to Go, etc.
In either case, the signal handler doesn't get run for an arbitrary period of time. And another signal could occur.
I didn't trace through the code to see how this is handled... but it seems like it is hard to handle simply and correctly (you're kind of recapitulating the problems of signals to begin with, in a higher level language).
Any docs / clarity on this would be interesting to me, as I will probably implement this in my own language soon.
Unless it changed, POSIX gives no guarantees of stack size and function calls re-entrancy guarantees depend a lot on the OS and compiler versions.
Hence the best approach in managed system languages is just to mark a signal as active and re-trigger it outside the handler when control gets back to user space.
(BTW, this is mostly a problem with signal handlers as a concept, not with Go.)
> The problem with using the syscall module is that Go does not export Fork and Exec. It exports ForkExec, because it needs to ensure they run on the same thread.
And because you can't safely allocate after a fork in managed languages, because fork drops your other threads, leading to the same problems above. :)