An interesting ‘bug’ in some versions of GCC (and Clang as well) implementation. Since it’s ‘undefined’ behavior after all, compiler is not obliged to implement it as a defined behavior. Use
-fwrapv flag in GCC to inform the compiler that integer value wraps.
Signal timeout for every small amount of time (say, 1ms in this case) and record the current stack, and we can infer time spent in each function precisely enough. A smart way of profiling large Python programs.
Note: python signal callback passes signal type and signal handler, and signal handler takes signal number and current stack frame.
Great book to Python, covering code style, best practices and scenario guide. Just started reading it.