code: def keyboard_interrupt(self):
          
          if self.multithreaded:
              self.interpreter.raise_keyboard_interrupt()
          else:
              if self.interpreter.more:
                  self.write_error("\nKeyboardInterrupt\n")
                  self.interpreter.more = False
                  self.new_prompt(self.interpreter.p1)
                  self.interpreter.resetbuffer()
              else:
                  self.interrupted = True
docs: Simulate keyboard interrupt