[英]Boto3/S3/Django: Avoid blocking the event loop while file hash being calculated
From a gunicorn+gevent worker, making (multipart) uploads to S3 via django-storages , how can I make sure that during the calculation of the hash of file/part contents, the event loop is not blocked? 从gunicorn + gevent工作者,通过django- storages将文件(分段)上传到S3,我如何确保在计算文件/部分内容的哈希值时,事件循环没有被阻止?
Looking in the source for django-storages , there doesn't really seem to be any scope for passing in the md5(/another hash), and in the source for botocore there doesn't seem to be scope for yielding the event loop while the hash is being calculated. 在django- storages的源代码中查找 ,似乎实际上没有传递md5(/另一个哈希值)的范围,在botocore的源代码中似乎没有产生事件循环的范围,而正在计算哈希值。
There is now a PR for django-storages that calculates the MD5 hash as data received by the application . 现在有django-storages的PR,可将MD5哈希计算为应用程序接收的数据 。
In summary, this changes S3Boto3StorageFile
so on init and new part 总之,这将更改
S3Boto3StorageFile
等init和新的部分
self._file_md5 = hashlib.md5()
and then on receive of content_bytes
然后收到
content_bytes
self._file_md5.update(content_bytes)
and then when each part is uploaded, the ContentMD5
parameter is passed to the part upload function 然后在上传每个零件时,将
ContentMD5
参数传递给零件上传功能
ContentMD5=base64.b64encode(self._file_md5.digest()).decode('utf-8')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.