]> kaliko git repositories - python-musicpd.git/commitdiff
Added tcp socket connection timeout
authorBart Van Loon <bbb@bbbart.be>
Sat, 23 Feb 2019 09:47:18 +0000 (10:47 +0100)
committerKaliko Jack <kaliko@azylum.org>
Tue, 26 Feb 2019 15:32:53 +0000 (16:32 +0100)
musicpd.py

index aae85a5f5348e897760cfe4248668a8b58047c68..e8f786324d5e24f9850512dccc5c2fdda51acab0 100644 (file)
@@ -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