挖掘代碼中的一點我發現multiprocessing.connection.Client
返回SocketClient
連接。在SocketClient
函數中定義了20秒的超時時間。如果在10 ms後沒有在此超時內建立連接,則會進行另一次嘗試。這將繼續下去,直到無窮遠:
CONNECTION_TIMEOUT = 20.
def _init_timeout(timeout=CONNECTION_TIMEOUT):
return time.time() + timeout
def _check_timeout(t):
return time.time() > t
def SocketClient(address):
'''
Return a connection object connected to the socket given by `address`
'''
family = address_type(address)
s = socket.socket(getattr(socket, family))
t = _init_timeout()
while 1:
try:
s.connect(address)
except socket.error, e:
if e.args[0] != errno.ECONNREFUSED or _check_timeout(t):
debug('failed to connect to address %s', address)
raise
time.sleep(0.01)
else:
break
else:
raise
fd = duplicate(s.fileno())
conn = _multiprocessing.Connection(fd)
s.close()
return conn
所以我相信我的問題的答案是,每次嘗試連接時,20秒的超時開始。如果在超過10毫秒後超時,則再次嘗試。