[Enhancement] Add error handler when getting host failed (#1374)

* [Enhancement] Add error handler when getting host failed

Signed-off-by: del-zhenwu <zhenxiang.li@zilliz.com>

* [Enhancement] Add error handler when getting host failed

Signed-off-by: del-zhenwu <zhenxiang.li@zilliz.com>

* [Enhancement] Add error handler when getting host failed

Signed-off-by: del-zhenwu <zhenxiang.li@zilliz.com>

* [Enhancement] Add error handler when getting host failed

Signed-off-by: del-zhenwu <zhenxiang.li@zilliz.com>
pull/1355/head^2
del-zhenwu 2021-10-14 13:49:45 +08:00 committed by GitHub
parent 42c9e71120
commit 70f902bb9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 1 deletions

View File

@ -3,6 +3,7 @@ import os
import random
import sys
import time
import warnings
from getpass import getuser
from socket import gethostname
@ -13,7 +14,18 @@ import mmcv
def get_host_info():
return f'{getuser()}@{gethostname()}'
"""Get hostname and username.
Return empty string if exception raised, e.g. ``getpass.getuser()`` will
lead to error in docker container
"""
host = ''
try:
host = f'{getuser()}@{gethostname()}'
except Exception as e:
warnings.warn(f'Host or user not found: {str(e)}')
finally:
return host
def get_time_str():