Add timeout for socket

This commit is contained in:
Lele Long 2014-02-12 17:26:58 +08:00
parent ce8cef35fa
commit 79f83e4ab4
1 changed files with 4 additions and 0 deletions

View File

@ -465,18 +465,22 @@ def speedtest():
parser.add_argument('--version', action='store_true',
help='Show the version number and exit')
parser.add_argument('--no-upload', action='store_true', help='no upload speed test')
parser.add_argument('--timeout', type=int, default=30, help='socket timeout in seconds(default to 30)')
options = parser.parse_args()
if isinstance(options, tuple):
args = options[0]
else:
args = options
del options
# Print the version and exit
if args.version:
version()
socket.setdefaulttimeout(args.timeout)
# If specified bind to a specific IP address
if args.source:
source = args.source