Skip to content

Instantly share code, notes, and snippets.

@zhreshold
Last active May 30, 2019 14:39
Show Gist options
  • Select an option

  • Save zhreshold/f4defab409cc0e6f6a0e75237f73ca99 to your computer and use it in GitHub Desktop.

Select an option

Save zhreshold/f4defab409cc0e6f6a0e75237f73ca99 to your computer and use it in GitHub Desktop.

Revisions

  1. zhreshold revised this gist Oct 15, 2017. 1 changed file with 129 additions and 38 deletions.
    167 changes: 129 additions & 38 deletions check_platform.py
    Original file line number Diff line number Diff line change
    @@ -1,52 +1,50 @@
    import platform, subprocess, sys
    """Diagnose script for checking OS/hardware/python/pip/mxnet/network.
    The output of this script can be a very good hint to issue/problem.
    """
    import platform, subprocess, sys, os
    import socket, time
    try:
    from urllib.request import urlopen
    from urllib.parse import urlparse
    except ImportError:
    from urlparse import urlparse
    from urllib2 import urlopen
    import argparse

    print('----------Python Info----------')
    print('Version :', platform.python_version())
    print('Compiler :', platform.python_compiler())
    print('Build :', platform.python_build())
    print('Arch :', platform.architecture())
    def parse_args():
    """Parse arguments."""
    parser = argparse.ArgumentParser(
    formatter_class=argparse.ArgumentDefaultsHelpFormatter,
    description='Diagnose script for checking the current system.')
    choices = ['python', 'pip', 'mxnet', 'os', 'hardware', 'network']
    for choice in choices:
    parser.add_argument('--' + choice, default=1, type=int,
    help='Diagnose {}.'.format(choice))
    parser.add_argument('--region', default='', type=str,
    help="Additional sites in which region(s) to test. \
    Specify 'cn' for example to test mirror sites in China.")
    parser.add_argument('--timeout', default=10, type=int,
    help="Connection test timeout threshold, 0 to disable.")
    args = parser.parse_args()
    return args

    print('----------System Info----------')
    print('Platform :', platform.platform())
    print('system :', platform.system())
    print('node :', platform.node())
    print('release :', platform.release())
    print('version :', platform.version())
    print('machine :', platform.machine())
    print('processor :', platform.processor())

    print('----------Hardware Info----------')
    if sys.platform.startswith('darwin'):
    pipe = subprocess.Popen(('sysctl', '-a'), stdout=subprocess.PIPE)
    output = pipe.communicate()[0]
    for line in output.split('\n'):
    if 'brand_string' in line or 'features' in line:
    print(line.strip())
    elif sys.platform.startswith('linux'):
    subprocess.call(['lscpu'])
    elif sys.platform.startswith('win32'):
    subprocess.call(['wmic', 'cpu', 'get', 'name'])

    print('----------Network Test----------')
    timeout = 10
    socket.setdefaulttimeout(timeout)
    URLS = {
    'Tutorial_site': 'https://zh.gluon.ai',
    'MXNet': 'https://github.com/apache/incubator-mxnet',
    'Gluon Tutorial(en)': 'http://gluon.mxnet.io',
    'Gluon Tutorial(cn)': 'https://zh.gluon.ai',
    'FashionMNIST': 'https://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/gluon/dataset/fashion-mnist/train-labels-idx1-ubyte.gz',
    'default_conda': 'https://repo.continuum.io/pkgs/free/',
    'conda_tsinghua_mirror': 'https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/',
    'default_pip': 'https://pypi.python.org/pypi/pip',
    'pip_douban_mirror': 'https://pypi.douban.com/simple'
    'PYPI': 'https://pypi.python.org/pypi/pip',
    'Conda': 'https://repo.continuum.io/pkgs/free/',
    }
    REGIONAL_URLS = {
    'cn': {
    'PYPI(douban)': 'https://pypi.douban.com/',
    'Conda(tsinghua)': 'https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/',
    }
    }

    def connection_test(name, url):
    def test_connection(name, url, timeout=10):
    """Simple connection test"""
    urlinfo = urlparse(url)
    start = time.time()
    try:
    @@ -64,5 +62,98 @@ def connection_test(name, url):
    load_elapsed = time.time() - start
    print("Timing for {}: {}, DNS: {:.4f} sec, LOAD: {:.4f} sec.".format(name, url, dns_elapsed, load_elapsed))

    for name, url in URLS.items():
    connection_test(name, url)
    def check_python():
    print('----------Python Info----------')
    print('Version :', platform.python_version())
    print('Compiler :', platform.python_compiler())
    print('Build :', platform.python_build())
    print('Arch :', platform.architecture())

    def check_pip():
    print('------------Pip Info-----------')
    try:
    import pip
    print('Version :', pip.__version__)
    print('Directory :', os.path.dirname(pip.__file__))
    except ImportError:
    print('No corresponding pip install for current python.')

    def check_mxnet():
    print('----------MXNet Info-----------')
    try:
    import mxnet
    print('Version :', mxnet.__version__)
    mx_dir = os.path.dirname(mxnet.__file__)
    print('Directory :', mx_dir)
    commit_hash = os.path.join(mx_dir, 'COMMIT_HASH')
    with open(commit_hash, 'r') as f:
    ch = f.read().strip()
    print('Commit Hash :', ch)
    except ImportError:
    print('No MXNet installed.')
    except Exception as e:
    import traceback
    if not isinstance(e, IOError):
    print("An error occured trying to import mxnet.")
    print("This is very likely due to missing missing or incompatible library files.")
    print(traceback.format_exc())

    def check_os():
    print('----------System Info----------')
    print('Platform :', platform.platform())
    print('system :', platform.system())
    print('node :', platform.node())
    print('release :', platform.release())
    print('version :', platform.version())

    def check_hardware():
    print('----------Hardware Info----------')
    print('machine :', platform.machine())
    print('processor :', platform.processor())
    if sys.platform.startswith('darwin'):
    pipe = subprocess.Popen(('sysctl', '-a'), stdout=subprocess.PIPE)
    output = pipe.communicate()[0]
    for line in output.split(b'\n'):
    if b'brand_string' in line or b'features' in line:
    print(line.strip())
    elif sys.platform.startswith('linux'):
    subprocess.call(['lscpu'])
    elif sys.platform.startswith('win32'):
    subprocess.call(['wmic', 'cpu', 'get', 'name'])

    def check_network(args):
    print('----------Network Test----------')
    if args.timeout > 0:
    print('Setting timeout: {}'.format(args.timeout))
    socket.setdefaulttimeout(10)
    for region in args.region.strip().split(','):
    r = region.strip().lower()
    if not r:
    continue
    if r in REGIONAL_URLS:
    URLS.update(REGIONAL_URLS[r])
    else:
    import warnings
    warnings.warn('Region {} do not need specific test, please refer to global sites.'.format(r))
    for name, url in URLS.items():
    test_connection(name, url, args.timeout)

    if __name__ == '__main__':
    args = parse_args()
    if args.python:
    check_python()

    if args.pip:
    check_pip()

    if args.mxnet:
    check_mxnet()

    if args.os:
    check_os()

    if args.hardware:
    check_hardware()

    if args.network:
    check_network(args)
  2. zhreshold revised this gist Sep 13, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion check_platform.py
    Original file line number Diff line number Diff line change
    @@ -39,7 +39,7 @@
    socket.setdefaulttimeout(timeout)
    URLS = {
    'Tutorial_site': 'https://zh.gluon.ai',
    'FashionMNIST_EU': 'http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/',
    'FashionMNIST': 'https://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/gluon/dataset/fashion-mnist/train-labels-idx1-ubyte.gz',
    'default_conda': 'https://repo.continuum.io/pkgs/free/',
    'conda_tsinghua_mirror': 'https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/',
    'default_pip': 'https://pypi.python.org/pypi/pip',
  3. zhreshold revised this gist Sep 12, 2017. 1 changed file with 24 additions and 7 deletions.
    31 changes: 24 additions & 7 deletions check_platform.py
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,11 @@
    import platform, subprocess, sys
    import socket, time, urllib, urlparse
    import socket, time
    try:
    from urllib.request import urlopen
    from urllib.parse import urlparse
    except ImportError:
    from urlparse import urlparse
    from urllib2 import urlopen

    print('----------Python Info----------')
    print('Version :', platform.python_version())
    @@ -29,23 +35,34 @@
    subprocess.call(['wmic', 'cpu', 'get', 'name'])

    print('----------Network Test----------')
    timeout = 10
    socket.setdefaulttimeout(timeout)
    URLS = {
    'Tutorial_site': 'https://zh.gluon.ai',
    'FashionMNIST_EU': 'http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/',
    'default_conda': 'https://repo.continuum.io/pkgs/free/',
    'conda_tsinghua_mirror': 'https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/',
    'default_pip': 'https://pypi.python.org/pypi/pip',
    'pip_douban_mirror': 'https://pypi.douban.com/simple'
    }

    def connection_test(name, url):
    urlinfo = urlparse.urlparse(url)
    urlinfo = urlparse(url)
    start = time.time()
    ip = socket.gethostbyname(urlinfo.netloc)
    try:
    ip = socket.gethostbyname(urlinfo.netloc)
    except Exception as e:
    print('Error resolving DNS for {}: {}, {}'.format(name, url, e))
    return
    dns_elapsed = time.time() - start
    start = time.time()
    _ = urllib.urlopen(url).read()
    try:
    _ = urlopen(url, timeout=timeout)
    except Exception as e:
    print("Error open {}: {}, {}, DNS finished in {} sec.".format(name, url, e, dns_elapsed))
    return
    load_elapsed = time.time() - start
    print("Timing for {}: {}, DNS: {:.4f} sec, LOAD: {:.4f} sec".format(name, url, dns_elapsed, load_elapsed))
    print("Timing for {}: {}, DNS: {:.4f} sec, LOAD: {:.4f} sec.".format(name, url, dns_elapsed, load_elapsed))

    for name, url in URLS.items():
    connection_test(name, url)

  4. zhreshold revised this gist Sep 12, 2017. 1 changed file with 23 additions and 0 deletions.
    23 changes: 23 additions & 0 deletions check_platform.py
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    import platform, subprocess, sys
    import socket, time, urllib, urlparse

    print('----------Python Info----------')
    print('Version :', platform.python_version())
    @@ -26,3 +27,25 @@
    subprocess.call(['lscpu'])
    elif sys.platform.startswith('win32'):
    subprocess.call(['wmic', 'cpu', 'get', 'name'])

    print('----------Network Test----------')
    URLS = {
    'Tutorial_site': 'https://zh.gluon.ai',
    'FashionMNIST_EU': 'http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/',
    'conda_tsinghua_mirror': 'https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/',
    'default_pip': 'https://pypi.python.org/pypi/pip',
    'pip_douban_mirror': 'https://pypi.douban.com/simple'
    }
    def connection_test(name, url):
    urlinfo = urlparse.urlparse(url)
    start = time.time()
    ip = socket.gethostbyname(urlinfo.netloc)
    dns_elapsed = time.time() - start
    start = time.time()
    _ = urllib.urlopen(url).read()
    load_elapsed = time.time() - start
    print("Timing for {}: {}, DNS: {:.4f} sec, LOAD: {:.4f} sec".format(name, url, dns_elapsed, load_elapsed))

    for name, url in URLS.items():
    connection_test(name, url)

  5. zhreshold created this gist Sep 11, 2017.
    28 changes: 28 additions & 0 deletions check_platform.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    import platform, subprocess, sys

    print('----------Python Info----------')
    print('Version :', platform.python_version())
    print('Compiler :', platform.python_compiler())
    print('Build :', platform.python_build())
    print('Arch :', platform.architecture())

    print('----------System Info----------')
    print('Platform :', platform.platform())
    print('system :', platform.system())
    print('node :', platform.node())
    print('release :', platform.release())
    print('version :', platform.version())
    print('machine :', platform.machine())
    print('processor :', platform.processor())

    print('----------Hardware Info----------')
    if sys.platform.startswith('darwin'):
    pipe = subprocess.Popen(('sysctl', '-a'), stdout=subprocess.PIPE)
    output = pipe.communicate()[0]
    for line in output.split('\n'):
    if 'brand_string' in line or 'features' in line:
    print(line.strip())
    elif sys.platform.startswith('linux'):
    subprocess.call(['lscpu'])
    elif sys.platform.startswith('win32'):
    subprocess.call(['wmic', 'cpu', 'get', 'name'])