I have a complex script which does I/O, lots of data processing, communication with external web services, etc.
In some rare cases the script 'hangs'. The CPU is at full 100% load all the time.
I would like to be able to debug the script and find the loop where is 'hangs'. But because it takes 2-3 hours before that loop is reached, I had another idea - print the full stack trace when I press a special key.
Is there a way to attach a keypress event to the script and then I press the right key, then the full stack trace (including where the script was before the keypress) would be printed?
Or maybe there is another solution?