mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-18 15:28:28 +01:00
lock: monkeypatch socket.getfqdn used by flufl.lock (#2628)
Workaround for slow and obsoleted gethostbyaddr used in `socket.getfqdn()`. See [1], [2] and [3] for more info. [1] https://bugs.python.org/issue5004 [2] https://github.com/iterative/dvc/issues/2582 [3] https://gitlab.com/warsaw/flufl.lock/merge_requests/12 Flufl.lock guys seem unresponsive, so we have to monkeypatch this by ourselves, at least for now. Fixes #2582
This commit is contained in:
+31
@@ -22,7 +22,38 @@ class LockError(DvcException):
|
||||
|
||||
|
||||
if is_py3:
|
||||
import socket
|
||||
|
||||
import flufl.lock
|
||||
from funcy import monkey
|
||||
|
||||
# Workaround for slow and obsoleted gethostbyaddr used in
|
||||
# `socket.getfqdn()`. See [1], [2] and [3] for more info.
|
||||
#
|
||||
# [1] https://bugs.python.org/issue5004
|
||||
# [2] https://github.com/iterative/dvc/issues/2582
|
||||
# [3] https://gitlab.com/warsaw/flufl.lock/merge_requests/12
|
||||
@monkey(socket)
|
||||
def getfqdn(name=""):
|
||||
"""Get fully qualified domain name from name.
|
||||
|
||||
An empty argument is interpreted as meaning the local host.
|
||||
"""
|
||||
name = name.strip()
|
||||
if not name or name == "0.0.0.0":
|
||||
name = socket.gethostname()
|
||||
try:
|
||||
addrs = socket.getaddrinfo(
|
||||
name, None, 0, socket.SOCK_DGRAM, 0, socket.AI_CANONNAME
|
||||
)
|
||||
except socket.error:
|
||||
pass
|
||||
else:
|
||||
for addr in addrs:
|
||||
if addr[3]:
|
||||
name = addr[3]
|
||||
break
|
||||
return name
|
||||
|
||||
class Lock(flufl.lock.Lock):
|
||||
"""Class for dvc repo lock.
|
||||
|
||||
Reference in New Issue
Block a user