0
我的要求是生成hundreds of HTTP POST requests per second
。我正在使用urllib2
。python多进程中进程的限制数
def send():
req = urllib2.Request(url)
req.add_data(data)
response = urllib2.urlopen(req)
while datetime.datetime.now() <= ftime:
p=Process(target=send, args=[])
p.start()
time.sleep(0.001)
问题是这样的代码sometimes for some iterations
抛出以下两种异常:
HTTP 503 Service Unavailable.
URLError: <urlopen error [Errno -2] Name or service not known>
我一直在使用requests(HTTP for humans)
也试过,但我有这个模块一些代理的问题。看起来像requests
即使目标机器位于同一LAN内,也会向代理服务器发送http数据包。我不希望数据包去代理服务器。
如果目标是产生大量的请求,我不会在那样的个别进程中启动这些请求。非常低效。使用扭曲和基于epoll的反应堆:http://twistedmatrix.com/documents/current/web/howto/client.html – agrinh
@agrinh感谢您的回复。你对如何在循环中使用Twisted有任何想法,我只能使用它生成单个请求。你能否提供一些代码片段? –
[多线程Python应用程序和套接字连接问题](http://stackoverflow.com/q/4783735/4279)具有代码示例,显示如何使用各种框架(例如'asyncio','twisted','' gevent'。 – jfs