8000 Change default connect_timeout to 10. · uwydoc/PyMySQL@e22a14a · GitHub
[go: up one dir, main page]

Skip to content

Commit e22a14a

Browse files
committed
1 parent 0e19ed3 commit e22a14a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

pymysql/connections.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ def __init__(self, host=None, user=None, password="",
530530
charset='', sql_mode=None,
531531
read_default_file=None, conv=None, use_unicode=None,
532532
client_flag=0, cursorclass=Cursor, init_command=None,
533-
connect_timeout=None, ssl=None, read_default_group=None,
533+
connect_timeout=10, ssl=None, read_default_group=None,
534534
compress=None, named_pipe=None, no_delay=None,
535535
autocommit=False, db=None, passwd=None, local_infile=False,
536536
max_allowed_packet=16*1024*1024, defer_connect=False,
@@ -564,6 +564,7 @@ def __init__(self, host=None, user=None, password="",
564564
cursorclass: Custom cursor class to use.
565565
init_command: Initial SQL statement to run when connection is established.
566566
connect_timeout: Timeout before throwing an exception when connecting.
567+
(default: 10, min: 1, max: 31536000)
567568
ssl:
568569
A dict of arguments similar to mysql_ssl_set()'s parameters.
569570
For now the capath and cipher arguments are not supported.
@@ -646,6 +647,9 @@ def _config(key, arg):
646647
self.db = database
647648
self.unix_socket = unix_socket
648649
self.bind_address = bind_address
650+
if not (0 < connect_timeout <= 31536000):
651+
raise ValueError("connect_timeout should be >0 and <=31536000")
652+
self.connect_timeout = connect_timeout or None
649653
if read_timeout is not None and read_timeout <= 0:
650654
raise ValueError("read_timeout should be >= 0")
651655
self._read_timeout = read_timeout
@@ -670,7 +674,6 @@ def _config(key, arg):
670674
self.client_flag = client_flag
671675

672676
self.cursorclass = cursorclass
673-
self.connect_timeout = connect_timeout or None
674677

675678
self._result = None
676679
self._affected_rows = 0

0 commit comments

Comments
 (0)
0