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()
I have Azure Blobs that need to download and upload(not shown). I do not want to wait for them to complete their process as I have other things that should be done. At some point though, I will need to confirm if they have successfully downloaded or uploaded.
With my current code, I have used the threading library. If an error happens in the upload or download process, the thread handling the transaction will exit with an error. I have no way to inform the main thread of completion and the status of the completion.
What do I need to do to be able to get the status of get_blob
? Is there a another library that has a less dangerous way of handling this situation? I have referenced the following threads but cannot figure out how to combine their different approaches.
Catch a thread's exception in the caller thread in Python
python multiprocessing pool retries