Python程序(网络请求)运行报错,新手无法理解,求指教
import urllib
import sys
url = "http://www.baidu.com"
for i in range(int(sys.argv[1])):
result = urllib.urlopen(url)
Windows环境,Python 2.7 最新版,我开了两个cmd运行这个程序,执行到一半会都出现如下IOError报错。不知道两个一起运行会有冲突吗?新手无法理解,是发生什么样的IO问题呢?
Traceback (most recent call last):
File "i13.py", line 4, in <module>
j12=urllib.urlopen("http://www.baidu.com")
File "C:\Python27\lib\urllib.py", line 87, in urlopen
return opener.open(url)
File "C:\Python27\lib\urllib.py", line 213, in open
return getattr(self, name)(url)
File "C:\Python27\lib\urllib.py", line 350, in open_http
h.endheaders(data)
File "C:\Python27\lib\httplib.py", line 1049, in endheaders
self._send_output(message_body)
File "C:\Python27\lib\httplib.py", line 893, in _send_output
self.send(msg)
File "C:\Python27\lib\httplib.py", line 855, in send
self.connect()
File "C:\Python27\lib\httplib.py", line 832, in connect
self.timeout, self.source_address)
File "C:\Python27\lib\socket.py", line 575, in create_connection
raise err
IOError: [Errno socket error] [Errno 10060]
我一个运行1000次,一个运行2000次,是不是跟一个窗口运行3000次是一样的?
==========================分割线==========================
import urllib2
import sys
from multiprocessing.dummy import Pool as ThreadPool
urls = ["http://www.baidu.com"]*int(sys.argv[1])
pool = ThreadPool(int(sys.argv[2]))
results = pool.map(urllib2.urlopen,urls)
pool.close()
pool.join()
运行这个程序test.py 10000 10,执行一半也会发生如下的错误
Traceback (most recent call last):
File "test.py", line 7, in <module>
results = pool.map(urllib2.urlopen,urls)
File "C:\Python27\lib\multiprocessing\pool.py", line 251, in map
return self.map_async(func, iterable, chunksize).get()
File "C:\Python27\lib\multiprocessing\pool.py", line 567, in get
raise self._value
urllib2.URLError: <urlopen error [Errno 10060] >
这个也是让我很疑惑,不知道从哪里着手好?请大牛指教。
F@ukTDN
9 years, 3 months ago