From 8499542b553b5184adbb839240874c5551dbb1ab Mon Sep 17 00:00:00 2001 From: Bart Van Loon Date: Sat, 23 Feb 2019 10:47:18 +0100 Subject: [PATCH] Added tcp socket connection timeout --- musicpd.py | 3 +++ 1 file changed, 3 insertions(+) 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 -- 2.39.5