Ask Your Question
0

What is the method for managing timeout when using Python SDK to upload a blob in Azure Storage?

asked 2023-06-08 22:47:35 +0000

nofretete gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-06-08 23:00:01 +0000

woof gravatar image

The method for managing timeout when using Python SDK to upload a blob in Azure Storage is to set the timeout parameter in the BlobServiceClient or the BlobClient constructor. The timeout parameter specifies the number of seconds the SDK will wait for the operation to complete before timing out.

For example, to set a timeout of 10 seconds when uploading a blob using the BlobClient, you can use the following code:

from azure.storage.blob import BlobServiceClient, BlobClient

blob_service_client = BlobServiceClient.from_connection_string("<your_connection_string>")
blob_client = blob_service_client.get_blob_client(container="<your_container_name>", blob="<your_blob_name>", timeout=10)

with open("path/to/local/file", "rb") as data:
    blob_client.upload_blob(data)

In this example, the timeout parameter is set to 10 seconds. If the upload operation takes longer than 10 seconds to complete, the SDK will raise a TimeoutError exception.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-08 22:47:35 +0000

Seen: 10 times

Last updated: Jun 08 '23