我有以下代码:
def whatever(url, data=None):
req = urllib2.Request(url)
res = urllib2.urlopen(req, data)
html = res.read()
res.close()
我尝试将它用于 GET ,如下所示:
for i in range(1,20):
whatever(someurl)
然后,在前 6 次行为正确后,它会阻塞 5 秒,并继续正常工作以进行其余 GET:
2012-06-29 15:20:22,487: Clear [127.0.0.1:49967]:
2012-06-29 15:20:22,507: Clear [127.0.0.1:49967]:
2012-06-29 15:20:22,528: Clear [127.0.0.1:49967]:
2012-06-29 15:20:22,552: Clear [127.0.0.1:49967]:
2012-06-29 15:20:22,569: Clear [127.0.0.1:49967]:
2012-06-29 15:20:22,592: Clear [127.0.0.1:49967]:
**2012-06-29 15:20:26,486: Clear [127.0.0.1:49967]:**
2012-06-29 15:20:26,515: Clear [127.0.0.1:49967]:
2012-06-29 15:20:26,555: Clear [127.0.0.1:49967]:
2012-06-29 15:20:26,586: Clear [127.0.0.1:49967]:
2012-06-29 15:20:26,608: Clear [127.0.0.1:49967]:
2012-06-29 15:20:26,638: Clear [127.0.0.1:49967]:
2012-06-29 15:20:26,655: Clear [127.0.0.1:49967]:
2012-06-29 15:20:26,680: Clear [127.0.0.1:49967]:
2012-06-29 15:20:26,700: Clear [127.0.0.1:49967]:
2012-06-29 15:20:26,717: Clear [127.0.0.1:49967]:
2012-06-29 15:20:26,753: Clear [127.0.0.1:49967]:
2012-06-29 15:20:26,770: Clear [127.0.0.1:49967]:
2012-06-29 15:20:26,789: Clear [127.0.0.1:49967]:
2012-06-29 15:20:26,809: Clear [127.0.0.1:49967]:
2012-06-29 15:20:26,828: Clear [127.0.0.1:49967]:
如果使用POST(with data={'a':'b'})
,则每个请求都会卡住 2 秒。我试过了urllib2
,pycurl
他们都给出了相同的结果。
有人对这种奇怪的行为有任何想法吗?