I am registering a signal for remote debugging:
signal.signal(signal.SIGUSR1, lambda x,y: remote_debug(x, y, emp_id))
While normally very fast, log statements show this command (register) sometimes takes 5 to 10 seconds to execute.  What is causing this? How can I fix it?
The Python callback code is not actually called right away in Python. The C code in Python just sets a flag when it gets a signal. It only runs the handler when it returns to the interpreter. If your code path is currently working in an extension module in compiled code the handler won't get run until it finishes.
The only way to fix it is to ensure that the execution path doesn't spend a lot of time in a C function. What function are you running at that time? Another culprit is the standard time.sleep() method. Use signal.pause() instead.
What can make signal.signal block for a long time?