mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-24 09:20:53 +07:00
IJ-CR-10044 PY-49021 Support interrupt in Python and Debug Console (including waiting for input case)
GitOrigin-RevId: 9eed8bb57194f3c698d2175de7d25d281444a14d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
d28247edef
commit
c0cb4e3973
@@ -149,53 +149,6 @@ class BaseInterpreterInterface(BaseCodeExecutor):
|
||||
traceback.print_exc()
|
||||
raise PythonUnhandledException(traceback.format_exc())
|
||||
|
||||
def interrupt(self):
|
||||
self.buffer = None # Also clear the buffer when it's interrupted.
|
||||
try:
|
||||
if self.interruptable:
|
||||
called = False
|
||||
try:
|
||||
# Fix for #PyDev-500: Console interrupt can't interrupt on sleep
|
||||
if os.name == 'posix':
|
||||
# On Linux we can't interrupt 0 as in Windows because it's
|
||||
# actually owned by a process -- on the good side, signals
|
||||
# work much better on Linux!
|
||||
os.kill(os.getpid(), signal.SIGINT)
|
||||
called = True
|
||||
|
||||
elif os.name == 'nt':
|
||||
# Stupid windows: sending a Ctrl+C to a process given its pid
|
||||
# is absurdly difficult.
|
||||
# There are utilities to make it work such as
|
||||
# http://www.latenighthacking.com/projects/2003/sendSignal/
|
||||
# but fortunately for us, it seems Python does allow a CTRL_C_EVENT
|
||||
# for the current process in Windows if pid 0 is passed... if we needed
|
||||
# to send a signal to another process the approach would be
|
||||
# much more difficult.
|
||||
# Still, note that CTRL_C_EVENT is only Python 2.7 onwards...
|
||||
# Also, this doesn't seem to be documented anywhere!? (stumbled
|
||||
# upon it by chance after digging quite a lot).
|
||||
os.kill(0, signal.CTRL_C_EVENT)
|
||||
called = True
|
||||
except:
|
||||
# Many things to go wrong (from CTRL_C_EVENT not being there
|
||||
# to failing import signal)... if that's the case, ask for
|
||||
# forgiveness and go on to the approach which will interrupt
|
||||
# the main thread (but it'll only work when it's executing some Python
|
||||
# code -- not on sleep() for instance).
|
||||
pass
|
||||
|
||||
if not called:
|
||||
if hasattr(thread, 'interrupt_main'): # Jython doesn't have it
|
||||
thread.interrupt_main()
|
||||
else:
|
||||
self.mainThread._thread.interrupt() # Jython
|
||||
self.finish_exec(False)
|
||||
return True
|
||||
except:
|
||||
traceback.print_exc()
|
||||
return False
|
||||
|
||||
def close(self):
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user