"apps/git@developer.sourcefind.cn:OpenDAS/dgl.git" did not exist on "f3b866f4eb32ad2c23e6deb7401e53b038b6f5e6"
Unverified Commit 4556fab8 authored by Jinjing Zhou's avatar Jinjing Zhou Committed by GitHub
Browse files

[Fix] Use logging to print warning message in socket creation (#3098)



* fix

* fix

* lint

* fix
Co-authored-by: default avatarQuan (Andy) Gan <coin2028@hotmail.com>
parent 22e8c120
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
import os import os
import socket import socket
import atexit import atexit
import logging
from . import rpc from . import rpc
from .constants import MAX_QUEUE_SIZE from .constants import MAX_QUEUE_SIZE
...@@ -13,9 +14,14 @@ if os.name != 'nt': ...@@ -13,9 +14,14 @@ if os.name != 'nt':
def local_ip4_addr_list(): def local_ip4_addr_list():
"""Return a set of IPv4 address """Return a set of IPv4 address
You can use
`logging.getLogger("dgl-distributed-socket").setLevel(logging.WARNING+1)`
to disable the warning here
""" """
assert os.name != 'nt', 'Do not support Windows rpc yet.' assert os.name != 'nt', 'Do not support Windows rpc yet.'
nic = set() nic = set()
logger = logging.getLogger("dgl-distributed-socket")
for if_nidx in socket.if_nameindex(): for if_nidx in socket.if_nameindex():
name = if_nidx[1] name = if_nidx[1]
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
...@@ -25,10 +31,9 @@ def local_ip4_addr_list(): ...@@ -25,10 +31,9 @@ def local_ip4_addr_list():
struct.pack('256s', name[:15].encode("UTF-8"))) struct.pack('256s', name[:15].encode("UTF-8")))
except OSError as e: except OSError as e:
if e.errno == 99: # EADDRNOTAVAIL if e.errno == 99: # EADDRNOTAVAIL
print("Warning!", logger.warning(
"Interface: {}".format(name), "Warning! Interface: %s \n"
"IP address not available for interface.", "IP address not available for interface.", name)
sep='\n')
continue continue
else: else:
raise e raise e
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment