Python gevent.socket 模块,gethostbyname() 实例源码

我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用gevent.socket.gethostbyname()

项目:Learning-Concurrency-in-Python    作者:PacktPublishing    | 项目源码 | 文件源码
def main():
  urls = ['www.google.com', 'www.example.com', 'www.python.org']
  jobs = [gevent.spawn(socket.gethostbyname, url) for url in urls]
  gevent.joinall(jobs, timeout=2)
  print([job.value for job in jobs])
项目:Intranet-Penetration    作者:yuxiaokui    | 项目源码 | 文件源码
def patch_dns():
    from gevent.socket import gethostbyname, getaddrinfo
    _socket = __import__('socket')
    _socket.getaddrinfo = getaddrinfo
    _socket.gethostbyname = gethostbyname
项目:MKFQ    作者:maojingios    | 项目源码 | 文件源码
def patch_dns():
    from gevent.socket import gethostbyname, getaddrinfo
    _socket = __import__('socket')
    _socket.getaddrinfo = getaddrinfo
    _socket.gethostbyname = gethostbyname
项目:web_develop    作者:dongweiming    | 项目源码 | 文件源码
def parse_address(address):
    try:
        hostname, port = address.rsplit(':', 1)
        port = int(port)
    except ValueError:
        sys.exit('Expected HOST:PORT: %r' % address)
    return gethostbyname(hostname), port
项目:xxNet    作者:drzorm    | 项目源码 | 文件源码
def patch_dns():
    from gevent.socket import gethostbyname, getaddrinfo
    _socket = __import__('socket')
    _socket.getaddrinfo = getaddrinfo
    _socket.gethostbyname = gethostbyname
项目:tinybitcoinpeer    作者:amiller    | 项目源码 | 文件源码
def main():
    with contextlib.closing(socket.socket()) as s, \
         contextlib.closing(s.makefile('wb',0)) as writer, \
         contextlib.closing(s.makefile('rb', 0)) as reader:

        # This will actually return a random testnet node
        their_ip = socket.gethostbyname("testnet-seed.bitcoin.schildbach.de")
        print("Connecting to:", their_ip)

        my_ip = "127.0.0.1"

        s.connect( (their_ip,PORT) )
        stream = msg_stream(reader)

        # Send Version packet
        send(writer, version_pkt(my_ip, their_ip))

        # Receive their Version
        their_ver = next(stream)
        print('Received:', their_ver)

        # Send Version acknolwedgement (Verack)
        send(writer, msg_verack())

        # Fork off a handler, but keep a tee of the stream
        stream = tee_and_handle(writer, stream)

        # Get Verack
        their_verack = next(stream)

        # Send a ping!
        try:
            while True:
                send(writer, msg_ping())
                send(writer, msg_getaddr())
                gevent.sleep(5)
        except KeyboardInterrupt: pass
项目:biji    作者:jianmoumou    | 项目源码 | 文件源码
def gg():
    import gevent
    from gevent import socket
    urls = ['www.baidu.com', 'www.qq.com', 'www.python.org']
    jobs = [gevent.spawn(socket.gethostbyname, url) for url in urls]
    gevent.joinall(jobs, timeout=2)
    print [job.value for job in jobs]
# gg()


# from urllib2 import urlopen
# import gevent, time
#
# from gevent import monkey  # ???????????IO??????????
# monkey.patch_all()   # ???
#
#
# def f(url):
#     print 'GET:%s' % url
#     resp = urlopen(url)
#     data = resp.read()
#     # file = open("data",'wb')#??????????????
#     # file.write(data)
#     print '%d bytes received from %s.' % (len(data), url)
#
# async_time_start = time.time()
# gevent.joinall([
#      gevent.spawn(f, 'https://www.python.org/'),
#      gevent.spawn(f, 'https://www.baidu.com/'),
#      gevent.spawn(f, 'https://github.com/')
#  ])
# print "???cost", time.time()-async_time_start

# pyquery
项目:Docker-XX-Net    作者:kuanghy    | 项目源码 | 文件源码
def patch_dns():
    from gevent.socket import gethostbyname, getaddrinfo
    _socket = __import__('socket')
    _socket.getaddrinfo = getaddrinfo
    _socket.gethostbyname = gethostbyname
项目:Concurrency-With-Python    作者:elliotforbes    | 项目源码 | 文件源码
def main():
  urls = ['www.google.com', 'www.example.com', 'www.python.org']
  jobs = [gevent.spawn(socket.gethostbyname, url) for url in urls]
  gevent.joinall(jobs, timeout=2)
  print([job.value for job in jobs])