如何用Python一次性上传多个文件到云文件?
我正在使用 cloudfile 模块 将文件上传到机架空间云文件,使用类似这样的伪代码
import cloudfiles
username = '---'
api_key = '---'
conn = cloudfiles.get_connection(username, api_key)
testcontainer = conn.create_container('test')
for f in get_filenames():
obj = testcontainer.create_object(f)
obj.load_from_filename(f)
:问题是我有很多小文件要上传,这样需要很长时间。
在文档中,我看到有一个类 ConnectionPool ,据说可以是用于并行上传文件。
有人可以告诉我如何使这段代码一次上传多个文件吗?
I'm using the cloudfile module to upload files to rackspace cloud files, using something like this pseudocode:
import cloudfiles
username = '---'
api_key = '---'
conn = cloudfiles.get_connection(username, api_key)
testcontainer = conn.create_container('test')
for f in get_filenames():
obj = testcontainer.create_object(f)
obj.load_from_filename(f)
My problem is that I have a lot of small files to upload, and it takes too long this way.
Buried in the documentation, I see that there is a class ConnectionPool, which supposedly can be used to upload files in parallell.
Could someone please show how I can make this piece of code upload more than one file at a time?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ConnectionPool
类适用于偶尔需要向机架空间发送内容的多线程应用程序。这样您就可以重用您的连接,但如果您有 100 个线程,则不必保持 100 个连接打开。
您只是在寻找多线程/多处理上传器。
以下是使用
multiprocessing
库的示例:The
ConnectionPool
class is meant for a multithreading application that ocasionally has to send something to rackspace.That way you can reuse your connection but you don't have to keep 100 connections open if you have 100 threads.
You are simply looking for a multithreading/multiprocessing uploader.
Here's an example using the
multiprocessing
library: