Workaround so only one CTRL-C is required for a new prompt in --gui=qt

Only implemented for posix systems. On Windows SIGINT kills python,
and signal.CTRL_C_EVENT doesn't do anything.
(cherry picked from commit 4c0c32097db2e49cb53b6c36c7366dac63e8008b)