Python Forum
python script is hanging while calling a procedure in database
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python script is hanging while calling a procedure in database
#1
Need help in how to maintain database connection alive

My python script is connecting to Oracle DB and is calling a stored procedure( this procedure will deletes data from table).The time taken for deletion of records from the table is taking more than 2 hrs.

After that python script is not executing the next set of commands, it is getting hanged in calling the procedure

please help how to fix this

My code:
import cx_Oracle
conn_str = "username/password@host:port/service"
d_dbh = cx_Oracle.connect(conn_str)
d_cursor = d_dbh.cursor()
d_cursor.execute(procedure_name)
d_cursor.execute("select count(1) from table_name)
delete_count = d_cursor.fetchone()[0]
print(delete_count)
As per the logs, the python script is hanged at calling that procedure. verified the logs from database end the records got deleted from table after 2hrs. but after 2hr the python script did not execute the next select statements.

Please help if this a session time out?
Larz60+ write Jan-16-2024, 11:14 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Code modified for you this time. Please use BBCode tags on future posts.
Reply
#2
Have you tried reconnecting?
Reply
#3
(Jan-16-2024, 03:49 PM)deanhystad Wrote: Have you tried reconnecting?

(Jan-17-2024, 12:34 PM)prasanthi417 Wrote: Before calling the procedure I am establishing conn to database
Reply
#4
- What interface are you using to manage the database? Does it hang or experience slowness?
- Did you try another language, does it also hangs or just python?
- Is your table large or did you indexes get dropped? Do you have dependencies in the data? Does this procedure execute properly if you do it through your DBMS interface?
- Have you look at the driver documentation, perhaps there is a known bug? Are you using the latest version? Is your driver version compatible with you python version?
- Check your connection string. Maybe there is something there that makes it behave weirdly. Try creating it in a different way.
- What OS are you running? Do you have a firewall/antivirus thing running? Perhaps they are killing your connection, try to disable them and see what happens.
- In my experience sometimes databases can work better if you "ping" them. Try to connect, and then disconnect and reconnect. Does it make any difference? How long does it take to connect?
- Is you DB hosted on your computer? Is it on a separate disk? Maybe that disk has issues/bad sectors/is dying. Check it's health.
Reply
#5
Have you tried making a new connection to the database after calling the procedure? Maybe the database dropped the old connection after 2 hours of inactivity.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Is there a *.bat DOS batch script to *.py Python Script converter? pstein 3 3,279 Jun-29-2023, 11:57 AM
Last Post: gologica
  python call stored procedure mg24 2 1,090 Oct-18-2022, 02:19 AM
Last Post: mg24
  python call stored procedure with two parameter mg24 4 1,534 Sep-27-2022, 05:02 AM
Last Post: deanhystad
  PyRun_SimpleFile calling multiprocessing Python Class cause endless init loop Xeno 2 1,056 Sep-19-2022, 02:32 AM
Last Post: Xeno
  Calling this script Extra 4 1,593 Jan-10-2022, 09:34 PM
Last Post: Extra
  Calling python from c++ in visual studio pdk5 0 2,174 May-24-2021, 10:18 AM
Last Post: pdk5
  Calling Oracle REST SQL from Python johnjacob 2 2,048 Nov-05-2020, 04:19 AM
Last Post: johnjacob
Bug maximum recursion depth exceeded while calling a Python object error in python3 Prezess 4 3,781 Aug-02-2020, 02:21 PM
Last Post: deanhystad
  How to kill a bash script running as root from a python script? jc_lafleur 4 5,939 Jun-26-2020, 10:50 PM
Last Post: jc_lafleur
  crontab on RHEL7 not calling python script wrapped in shell script benthomson 1 2,314 May-28-2020, 05:27 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020