I've just created an script with a long time query, and I added a signal handled that when I press CTRL+C, it launches a connection.close()
.
But when I run the py script and press CTRL+C it just waits until the execute has ended to handle the signal.
Is there any way I can cancel it while running?
def signal_term_handler(signal, frame):
connection.cancel()
sys.exit('Excution stopped manually.')
ip = IP
port = PORT
SID = SID
dsn_tns = cx_Oracle.makedsn(ip, port, SID)
connection = cx_Oracle.connect(USER, PASS, dsn_tns)
cursor = connection.cursor()
signal.signal(signal.SIGTERM, signal_term_handler)
signal.signal(signal.SIGINT, signal_term_handler)
cursor.execute(QUERY)
QUERY
is a query with multiple selects that lasts for around 4 minutes.