In my python program I need to catch the WINCH signal like this:
def WinResize(num, stack):
# DO SOME STUFF HERE
signal.signal(signal.SIGWINCH, WinResize)
The problem is that readline doesn't get the signal and its internal view of the window is false. I tried a trick using
readline.set_completer(readline.get_completer())
at the end of the WinResize function which partially solves my problem but not completely. With this solution, the new size is updated on readline if i continue to give input until it goes to newline. Until that point it has internally the previous size.
If I don't catch the signal, readline works as expected. I want to completely solve this issue.
Here is a video that demonstrates the issue: https://streamable.com/1tja9g
Finally after countless experiments I found the solution to my problem. When I import the readline module AFTER setting up my WINCH signal handler it works as expected. I don't know why though.