From e22a14a10019f3fc57c548e3fde7316396cd8a60 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Thu, 12 Jan 2017 21:11:51 +0900 Subject: [PATCH] Change default connect_timeout to 10. Use same default value https://dev.mysql.com/doc/refman/5.6/en/server-system-variables.html#sysvar_connect_timeout --- pymysql/connections.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pymysql/connections.py b/pymysql/connections.py index 3018c06e..a2094d8f 100644 --- a/pymysql/connections.py +++ b/pymysql/connections.py @@ -530,7 +530,7 @@ def __init__(self, host=None, user=None, password="", charset='', sql_mode=None, read_default_file=None, conv=None, use_unicode=None, client_flag=0, cursorclass=Cursor, init_command=None, - connect_timeout=None, ssl=None, read_default_group=None, + connect_timeout=10, ssl=None, read_default_group=None, compress=None, named_pipe=None, no_delay=None, autocommit=False, db=None, passwd=None, local_infile=False, max_allowed_packet=16*1024*1024, defer_connect=False, @@ -564,6 +564,7 @@ def __init__(self, host=None, user=None, password="", cursorclass: Custom cursor class to use. init_command: Initial SQL statement to run when connection is established. connect_timeout: Timeout before throwing an exception when connecting. + (default: 10, min: 1, max: 31536000) ssl: A dict of arguments similar to mysql_ssl_set()'s parameters. For now the capath and cipher arguments are not supported. @@ -646,6 +647,9 @@ def _config(key, arg): self.db = database self.unix_socket = unix_socket self.bind_address = bind_address + if not (0 < connect_timeout <= 31536000): + raise ValueError("connect_timeout should be >0 and <=31536000") + self.connect_timeout = connect_timeout or None if read_timeout is not None and read_timeout <= 0: raise ValueError("read_timeout should be >= 0") self._read_timeout = read_timeout @@ -670,7 +674,6 @@ def _config(key, arg): self.client_flag = client_flag self.cursorclass = cursorclass - self.connect_timeout = connect_timeout or None self._result = None self._affected_rows = 0