|
| 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