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 c86cf86f1805cf66c24f17336044c16531d737da)