【发布时间】:2018-05-01 20:10:35
【问题描述】:
import threading
from azure.storage.blob import BlockBlobService
def do_other_stuff():
print("so much stuff to do")
class ABlob:
def __init__(self, account_name, account_key, container_name, blob_name, file_path):
self.account_name = account_name
self.account_key = account_key
self.container_name = container_name
self.blob_name = blob_name
self.file_path = file_path
self.blob_service = BlockBlobService(account_name=self.account_name, account_key=self.account_key)
def get_blob(self):
download_thread = threading.Thread(
target=self.blob_service.get_blob_to_path,
args=(self.container_name, self.blob_name, self.file_path))
download_thread.start()
def get_blob_name(self):
print(self.blob_name)
first_blob = ABlob(account_name='account_name',
account_key='key',
container_name='container', blob_name='something.csv',
file_path='path')
first_blob.get_blob()
first_blob.get_blob_name()
do_other_stuff()
我有需要下载和上传的 Azure Blob(未显示)。我不想等待他们完成他们的过程,因为我还有其他事情要做。但在某些时候,我需要确认它们是否已成功下载或上传。
在我当前的代码中,我使用了线程库。如果上传或下载过程中发生错误,处理事务的线程将退出并返回错误。我没有办法通知主线程完成和完成的状态。
我需要做什么才能获得get_blob 的状态?是否有另一个图书馆以一种不那么危险的方式来处理这种情况?我引用了以下线程,但无法弄清楚如何组合它们的不同方法。
Catch a thread's exception in the caller thread in Python
python multiprocessing pool retries
【问题讨论】:
标签: python multithreading asynchronous python-multithreading python-asyncio