Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit aaa84fe

Browse files
committedMar 15, 2019
Add sample for using the call timeout feature available with cx_Oracle 7.0 and
Oracle Client 18.1 and higher.
1 parent c1e1659 commit aaa84fe

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
 

‎doc/src/connection.rst

+2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ Connection Object
7474
that a single round-trip to the database may take before a timeout will
7575
occur. A value of 0 means that no timeout will take place.
7676

77+
.. versionadded:: 7.0
78+
7779
.. note::
7880

7981
This attribute is an extension to the DB API definition and is only

‎samples/CallTimeout.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#------------------------------------------------------------------------------
2+
# Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
3+
#------------------------------------------------------------------------------
4+
5+
#------------------------------------------------------------------------------
6+
# CallTimeout.py
7+
#
8+
# Demonstrate the use of the Oracle Client 18c feature that enables round trips
9+
# to the database to time out if a specified amount of time (in milliseconds)
10+
# has passed without a response from the database.
11+
#
12+
# This script requires cx_Oracle 7.0 and higher and Oracle Client 18.1 and
13+
# higher.
14+
#------------------------------------------------------------------------------
15+
16+
from __future__ import print_function
17+
18+
import cx_Oracle
19+
import SampleEnv
20+
21+
connection = cx_Oracle.connect(SampleEnv.GetMainConnectString())
22+
connection.callTimeout = 2000
23+
print("Call timeout set at", connection.callTimeout, "milliseconds...")
24+
25+
cursor = connection.cursor()
26+
cursor.execute("select sysdate from dual")
27+
today, = cursor.fetchone()
28+
print("Fetch of current date before timeout:", today)
29+
30+
print("Sleeping...should time out...")
31+
try:
32+
cursor.callproc("dbms_lock.sleep", (3,))
33+
except cx_Oracle.DatabaseError as e:
34+
print("ERROR:", e)
35+
36+
cursor.execute("select sysdate from dual")
37+
today, = cursor.fetchone()
38+
print("Fetch of current date after timeout:", today)
39+

0 commit comments

Comments
 (0)
Please sign in to comment.