简体   繁体   English

Python urllib2错误

[英]Python urllib2 Errors

I have a long list of URLs I need to open for my service. 我有一长串需要为我的服务打开的URL。 Whenever I attempt to open this entire list, I receive many errors such as this when I initiate the program: [Errno 24] Too many open files . 每当我尝试打开整个列表时,我会在启动程序时收到许多错误: [Errno 24] Too many open files I am using urllib2 and gevent. 我正在使用urllib2和gevent。

Does anyone have any solutions? 有没有人有任何解决方案?

Thanks. 谢谢。

使用Gevent.pool一次只打开一定数量的url然后在打开url时重用这些greenlet。

As we still don't know what you exactly do, I can only guess: you are opening many URLs at once, and only then you try to read them. 由于我们仍然不知道你到底做了什么,我只能猜测:你一次打开许多网址,然后才尝试阅读它们。 Instead, you should/could open-read-close them and then advance to the next one. 相反,你应该/可以打开 - 读取 - 关闭它们然后前进到下一个。

Alternatively, you could create a concurrency capable URL loader: open some urls and try to read them concurrently. 或者,您可以创建一个支持并发的URL加载器:打开一些 URL并尝试同时读取它们。 After closing one, you can start opening the next. 关闭之后,您可以开始打开下一个。 If you limit that to 5 or 10 at once, you shouldn't get a problem any longer. 如果您一次将其限制为5或10,则不应再出现问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM