Files
pide/script/test/test_abort.py
2022-08-30 15:12:26 +02:00

51 lines
1.3 KiB
Python

"""
import ctypes
def ctype_async_raise(thread, exception):
tid=thread.ident
print (1)
ret = ctypes.pythonapi.PyThreadState_SetAsyncExc(ctypes.c_long(tid), ctypes.py_object(exception))
# ref: http://docs.python.org/c-api/init.html#PyThreadState_SetAsyncExc
print (2)
if ret == 0:
raise ValueError("Invalid thread ID")
elif ret > 1:
# Huh? Why would we notify more than one threads?
# Because we punch a hole into C level interpreter.
# So it is better to clean up the mess.
ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, NULL)
raise SystemError("PyThreadState_SetAsyncExc failed")
import signal
"""
def on_abort(parent_thread):
print ("on_abort")
tid=parent_thread.ident
exception = KeyboardInterrupt
ctypes.pythonapi.PyThreadState_SetAsyncExc(ctypes.c_long(tid), ctypes.py_object(exception))
def on_close(parent_thread):
print ("on_close")
on_abort(parent_thread)
#def handler(signum, frame):
# print('Signal handler called with signal', signum)
# #
#
# Set the signal handler and a 5-second alarm
#signal.signal(signal.SIGINT, handler)
time.sleep(2.0)
print (1)
time.sleep(2.0)
print (2)
time.sleep(2.0)
print (3)
time.sleep(2.0)
print (4)
time.sleep(2.0)
print (5)