From: Bart Van Loon Date: Sat, 23 Feb 2019 09:47:18 +0000 (+0100) Subject: Added tcp socket connection timeout X-Git-Tag: v0.4.4~2 X-Git-Url: https://git.kaliko.me/?a=commitdiff_plain;h=8499542b553b5184adbb839240874c5551dbb1ab;p=python-musicpd.git Added tcp socket connection timeout --- diff --git a/musicpd.py b/musicpd.py index aae85a5..e8f7863 100644 --- a/musicpd.py +++ b/musicpd.py @@ -30,6 +30,7 @@ SUCCESS = "OK" NEXT = "list_OK" VERSION = '0.4.4' +CONNECTION_TIMEOUT = 5 # seconds before a tcp connection attempt times out def iterator_wrapper(func): """Decorator handling iterate option""" @@ -556,7 +557,9 @@ class MPDClient: sock = None try: sock = socket.socket(af, socktype, proto) + sock.settimeout(CONNECTION_TIMEOUT) sock.connect(sa) + sock.settimeout(None) return sock except socket.error as socket_err: err = socket_err