Skip to content

Commit 91e0625

Browse files
committed
Add connection timeout and read timeout support.
1 parent 3872276 commit 91e0625

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

pycovenantsql/connections.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Connection(object):
2525
:param key: Private key to access database.
2626
:param database: Database id to use. uri and database should set at least one.
2727
:param read_timeout: The timeout for reading from the connection in seconds (default: None - no timeout)
28-
:param write_timeout: The timeout for writing to the connection in seconds (default: None - no timeout)
28+
#(Not supported now):param write_timeout: The timeout for writing to the connection in seconds (default: None - no timeout)
2929
:param read_default_file:
3030
Specifies my.cnf file to read these parameters from under the [client] section.
3131
:param cursorclass: Custom cursor class to use.
@@ -42,8 +42,8 @@ class Connection(object):
4242

4343
def __init__(self, dsn=None, host=None, port=0, key=None, database=None,
4444
https_pem=None, read_default_file=None,
45-
cursorclass=Cursor, connect_timeout=10, read_default_group=None,
46-
read_timeout=None, write_timeout=None):
45+
cursorclass=Cursor, connect_timeout=None, read_default_group=None,
46+
read_timeout=None):
4747

4848
self._resp = None
4949

@@ -99,15 +99,15 @@ def _config(key, arg):
9999
else:
100100
self._cert = self.key
101101

102-
if not (0 < connect_timeout <= 31536000):
103-
raise ValueError("connect_timeout should be >0 and <=31536000")
104-
self.connect_timeout = connect_timeout or None
102+
self.timeout = None
103+
if connect_timeout is not None and connect_timeout <= 0:
104+
raise ValueError("connect_timeout should be >= 0")
105105
if read_timeout is not None and read_timeout <= 0:
106106
raise ValueError("read_timeout should be >= 0")
107-
self._read_timeout = read_timeout
108-
if write_timeout is not None and write_timeout <= 0:
109-
raise ValueError("write_timeout should be >= 0")
110-
self._write_timeout = write_timeout
107+
#if write_timeout is not None and write_timeout <= 0:
108+
# raise ValueError("write_timeout should be >= 0")
109+
if connect_timeout is not None or read_timeout is not None:
110+
self.timeout = (connect_timeout, read_timeout)
111111

112112
self.cursorclass = cursorclass
113113

@@ -227,7 +227,7 @@ def _send(self, uri, data):
227227
session = requests.Session()
228228
session.verify = False
229229
session.cert = self._cert
230-
return session.post(uri, data)
230+
return session.post(uri, data, timeout=self.timeout)
231231

232232
def escape(self, obj, mapping=None):
233233
"""Escape whatever value you pass to it.

0 commit comments

Comments
 (0)