Skip to content

Commit

Permalink
Update samples (#33815)
Browse files Browse the repository at this point in the history
* Update samples

* updates
  • Loading branch information
xiangyan99 authored Jan 18, 2024
1 parent 3dc8333 commit fee8bcf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
24 changes: 12 additions & 12 deletions sdk/core/azure-core/samples/example_shared_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,25 @@

def shared_transport():
# [START shared_transport]
shared_transport = RequestsTransport()
import requests

session = requests.Session()
shared_transport = RequestsTransport(
session=session, session_owner=False
) # here we set session_owner to False to indicate that we don't want to close the session when the client is closed
with shared_transport:
blob_service_client1 = BlobServiceClient.from_connection_string(
connection_string,
transport=shared_transport,
session_owner=False, # here we set session_owner to False to indicate that we don't want to close the session when the client is closed
)
blob_service_client2 = BlobServiceClient.from_connection_string(
connection_string, transport=shared_transport, session_owner=False
)
blob_service_client2 = BlobServiceClient.from_connection_string(connection_string, transport=shared_transport)
containers1 = blob_service_client1.list_containers()
for contain in containers1:
print(contain.name)
containers2 = blob_service_client2.list_containers()
for contain in containers2:
print(contain.name)
session.close() # we need to close the session manually
# [END shared_transport]


Expand All @@ -55,20 +58,17 @@ def shared_transport_with_pooling():
adapter = requests.adapters.HTTPAdapter(pool_connections=100, pool_maxsize=100)
session.mount("http://", adapter)
session.mount("https://", adapter)
shared_transport = RequestsTransport(session=session)
shared_transport = RequestsTransport(session=session, session_owner=False)
with shared_transport:
blob_service_client1 = BlobServiceClient.from_connection_string(
connection_string, transport=shared_transport, session_owner=False
)
blob_service_client2 = BlobServiceClient.from_connection_string(
connection_string, transport=shared_transport, session_owner=False
)
blob_service_client1 = BlobServiceClient.from_connection_string(connection_string, transport=shared_transport)
blob_service_client2 = BlobServiceClient.from_connection_string(connection_string, transport=shared_transport)
containers1 = blob_service_client1.list_containers()
for contain in containers1:
print(contain.name)
containers2 = blob_service_client2.list_containers()
for contain in containers2:
print(contain.name)
session.close() # we need to close the session manually
# [END shared_transport_with_pooling]


Expand Down
24 changes: 12 additions & 12 deletions sdk/core/azure-core/samples/example_shared_transport_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,25 @@

async def shared_transport_async():
# [START shared_transport_async]
shared_transport = AioHttpTransport()
import aiohttp

session = aiohttp.ClientSession()
shared_transport = AioHttpTransport(
session=session, session_owner=False
) # here we set session_owner to False to indicate that we don't want to close the session when the client is closed
async with shared_transport:
blob_service_client1 = BlobServiceClient.from_connection_string(
connection_string,
transport=shared_transport,
session_owner=False, # here we set session_owner to False to indicate that we don't want to close the session when the client is closed
)
blob_service_client2 = BlobServiceClient.from_connection_string(
connection_string, transport=shared_transport, session_owner=False
)
blob_service_client2 = BlobServiceClient.from_connection_string(connection_string, transport=shared_transport)
containers1 = blob_service_client1.list_containers()
async for contain in containers1:
print(contain.name)
containers2 = blob_service_client2.list_containers()
async for contain in containers2:
print(contain.name)
await session.close() # we need to close the session manually
# [END shared_transport_async]


Expand All @@ -54,20 +57,17 @@ async def shared_transport_async_with_pooling():

conn = aiohttp.TCPConnector(limit=100)
session = aiohttp.ClientSession(connector=conn)
shared_transport = AioHttpTransport(session=session)
shared_transport = AioHttpTransport(session=session, session_owner=False)
async with shared_transport:
blob_service_client1 = BlobServiceClient.from_connection_string(
connection_string, transport=shared_transport, session_owner=False
)
blob_service_client2 = BlobServiceClient.from_connection_string(
connection_string, transport=shared_transport, session_owner=False
)
blob_service_client1 = BlobServiceClient.from_connection_string(connection_string, transport=shared_transport)
blob_service_client2 = BlobServiceClient.from_connection_string(connection_string, transport=shared_transport)
containers1 = blob_service_client1.list_containers()
async for contain in containers1:
print(contain.name)
containers2 = blob_service_client2.list_containers()
async for contain in containers2:
print(contain.name)
await session.close() # we need to close the session manually
# [END shared_transport_async_with_pooling]


Expand Down

0 comments on commit fee8bcf

Please sign in to comment.