为什么urlopen在eventlet spawn函数中超时

时间:2015-05-26 11:20:49

标签: timeout urlopen eventlet

我遇到了一个奇怪的问题:
eventlet.green.urllib2.urlopen()引发HTTP错误408:请求超时。
但是如果打开“#eventlet.green.time.sleep(0.1)”就成功了
有谁知道为什么?非常感谢!

test.py:

import eventlet
import eventlet.green.urllib2

pool = eventlet.GreenPool()
status = "idling"

url_list = [
   "http://192.168.1.218:1995/api/v1/srs_conf", # valid url
   "http://192.168.1.163:1995/api/v1/srs_conf", # valid url
   "http://safsawegdffsd:1995/api/v1/srs_conf", # invalid urls followed
   "http://sddsadfggdfsd:1995/api/v1/srs_conf",
   "http://safsadffddfsd:1995/api/v1/srs_conf",
   "http://safsssadffdsd:1995/api/v1/srs_conf",
   "http://sarsadfggdfsd:1995/api/v1/srs_conf",
   "http://werweer3fsfgv:1995/api/v1/srs_conf"
]

def do_get(url):
    conn = None
    try:
        conn = eventlet.green.urllib2.urlopen(url)
        res = conn.read()
        print res
    except Exception, ex:
        print url, ex
    finally:
        if conn:
            conn.close()

def start():
    for i in range(len(url_list)):
        pool.spawn_n(do_get, url_list[i])
        # eventlet.green.time.sleep(0.1)

while True:
    if status == "idling":
        status = "running"
        start()
    eventlet.green.time.sleep(1)

结果:

http://safsadffddfsd:1995/api/v1/srs_conf <urlopen error [Errno 11004] getaddrinfo failed>
http://sddsadfggdfsd:1995/api/v1/srs_conf <urlopen error [Errno 11004] getaddrinfo failed>
http://safsssadffdsd:1995/api/v1/srs_conf <urlopen error [Errno 11004] getaddrinfo failed>
http://safsawegdffsd:1995/api/v1/srs_conf <urlopen error [Errno 11004] getaddrinfo failed>
http://sarsadfggdfsd:1995/api/v1/srs_conf <urlopen error [Errno 11004] getaddrinfo failed>
http://werweer3fsfgv:1995/api/v1/srs_conf <urlopen error [Errno 11004] getaddrinfo failed>
http://192.168.1.218:1995/api/v1/srs_conf <urlopen error [Errno 10061] WSAECONNREFUSED>
http://192.168.1.163:1995/api/v1/srs_conf HTTP Error 408: Request Timeout

0 个答案:

没有答案