Skip to content

Cancel a cursor.execute() #173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sergiownd opened this issue Apr 26, 2018 · 13 comments
Closed

Cancel a cursor.execute() #173

sergiownd opened this issue Apr 26, 2018 · 13 comments
Labels

Comments

@sergiownd
Copy link

Hi, I'm running a query which takes a long time to finish. I want to be able to kill the connection with CTRL+C or kill PID. I've tried to use the connection.cancel() o the terminate process but the query keeps on executing. I've also tried to make the query on a subprocess but even if i kill the process the query is still executed. Is there any way of cancelling it?

Thanks.

@sergiownd sergiownd changed the title Cancell a cursor.execute() Cancel a cursor.execute() Apr 26, 2018
@anthony-tuininga
Copy link
Member

Can you provide some more information on platform, Oracle versions (database and client), cx_Oracle version. It would also be helpful if you can include the code you used so we can see if your use of cancel() is being done correctly! Thanks.

@sergiownd
Copy link
Author

sergiownd commented Apr 26, 2018

Here is the code:

import cx_Oracle
import sys
import signal

def signal_term_handler(signal, frame):
    connection.cancel()
    sys.exit('end')

ip = 'localhost'
port = 49161
SID = 'xe'
dsn_tns = cx_Oracle.makedsn(ip, port, SID)
connection = cx_Oracle.connect('system', 'oracle', dsn_tns)
cursor = connection.cursor()

signal.signal(signal.SIGTERM, signal_term_handler)
signal.signal(signal.SIGINT, signal_term_handler)
cursor.execute("create table testear as select * from test union select * from test2 union select * from test3 union select * from test2 union select * from test3 union select * from test2 union select * from test3 union select * from test2 union select * from test3 union select * from test2 union select * from test3 union select * from test2 union select * from test3 union select * from test2 union select * from test3 union select * from test2 union select * from test3 union select * from test2 union select * from test3 union select * from test2 union select * from test3 union select * from test2 union select * from test3 union select * from test2 union select * from test3")


return()

I've also used cursor.close() on the signal process, declaring the cursor earlier, and nothing. The process stops but the query is still launched.
I've also tried stop it with multi process:

ip = 'localhost'
port = 49161
SID = 'xe'
dsn_tns = cx_Oracle.makedsn(ip, port, SID)
connection = cx_Oracle.connect('system', 'oracle', dsn_tns)
cursor = connection.cursor()

def signal_term_handler(signal, frame):
    cursor.close()
    sys.exit('Excution stopped manually.')

def threat_treatment():
	cursor.execute("create table testear as select * from test union select * from test2 union select * from test3 union select * from test2 union select * from test3 union select * from test2 union select * from test3 union select * from test2 union select * from test3 union select * from test2 union select * from test3 union select * from test2 union select * from test3 union select * from test2 union select * from test3 union select * from test2 union select * from test3 union select * from test2 union select * from test3 union select * from test2 union select * from test3 union select * from test2 union select * from test3 union select * from test2 union select * from test3")


t1 = Process(target=threat_treatment)
t1.start()
signal.signal(signal.SIGTERM, signal_term_handler)
signal.signal(signal.SIGINT, signal_term_handler)
t1.join()

return(1)

I'm using the latest version of cx_oracle, and I'm user docker to prepare the database with oracle-xe-11g.

The connection with the database works good. The table is created, the problem is that I cannot cancel it.

Thank you for helping

@cjbj
Copy link
Member

cjbj commented Apr 26, 2018

@sergiownd
Copy link
Author

Yes, actually It is my post too.

@cjbj
Copy link
Member

cjbj commented Apr 27, 2018

Check the firewall or try DISABLE_OOB=on in a sqlnet.ora. And post platform and version details too, please!

@sergiownd
Copy link
Author

Where should I add the DISABLE_OOB=on (I'm some kind of new to Oracle) Thanks. And about platform I dont know if u mean my machine or what else.

@cjbj
Copy link
Member

cjbj commented Apr 27, 2018

This has some applicable info https://oracle.github.io/node-oracledb/doc/api.html#tnsadmin (the network layer is common with cx_Oracle)

Platform == whatever you are running on: operating system, virtual machines etc.

@sergiownd
Copy link
Author

I'm running the code on a Ubuntu Budgie and the data base running on a docker (oracle-xe-11g)

@anthony-tuininga
Copy link
Member

Closing due to lack of activity.

@vbvasu
Copy link

vbvasu commented Feb 8, 2024

Hi,
Im trying to execute like 15-20 queries using cx_oracle python
Some of the queries may run long sometimes i am searching for a way to stop the query if its still running for more than 30 min i would like to skip this and cancel the execution and gopn executing other queries.
Is there anyway to track the time and cancel the query execution and skip this

@anthony-tuininga
Copy link
Member

Take a look at the attribute call_timeout. This is for the replacement for cx_Oracle called python-oracledb but the same information applies to cx_Oracle.

@vbvasu
Copy link

vbvasu commented Feb 9, 2024

I dont think it will help me resolving the issue.

@anthony-tuininga
Copy link
Member

Why do you think that? Open a new issue with details!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants