We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(5)
这是我的线程映射的实现:
Here is my implementation of threaded map:
Python 模块
Queue
可能会帮助你。使用一个线程,该线程使用Queue.put()
将所有 url 推送到队列中,工作线程只需get()
一一地获取 URL。Python 文档:queue — 同步队列类
The Python module
Queue
might help you. Use one thread that usesQueue.put()
to push all urls into the queue and the worker threads simplyget()
the urls one by one.Python Docs: queue — A synchronized queue class
我将其包装在一个函数中(未经测试):
I'd wrap it up in a function (untested):
multiprocessing.Pool< 中有一个
map
方法/a>.这会执行多个进程。如果多个进程不是你的菜,你可以使用 multiprocessing.dummy< /a> 使用线程。
There is a
map
method in multiprocessing.Pool. That does multiple processes.And if multiple processes aren't your dish, you can use multiprocessing.dummy which uses threads.
有人建议我为此使用
futures
包。我尝试了一下,似乎有效。http://pypi.python.org/pypi/futures
这是一个示例:
Someone recommended I use the
futures
package for this. I tried it and it seems to be working.http://pypi.python.org/pypi/futures
Here's an example: