29
29
30
30
async def shared_transport_async ():
31
31
# [START shared_transport_async]
32
- shared_transport = AioHttpTransport ()
32
+ import aiohttp
33
+
34
+ session = aiohttp .ClientSession ()
35
+ shared_transport = AioHttpTransport (
36
+ session = session , session_owner = False
37
+ ) # here we set session_owner to False to indicate that we don't want to close the session when the client is closed
33
38
async with shared_transport :
34
39
blob_service_client1 = BlobServiceClient .from_connection_string (
35
40
connection_string ,
36
41
transport = shared_transport ,
37
- 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
38
- )
39
- blob_service_client2 = BlobServiceClient .from_connection_string (
40
- connection_string , transport = shared_transport , session_owner = False
41
42
)
43
+ blob_service_client2 = BlobServiceClient .from_connection_string (connection_string , transport = shared_transport )
42
44
containers1 = blob_service_client1 .list_containers ()
43
45
async for contain in containers1 :
44
46
print (contain .name )
45
47
containers2 = blob_service_client2 .list_containers ()
46
48
async for contain in containers2 :
47
49
print (contain .name )
50
+ await session .close () # we need to close the session manually
48
51
# [END shared_transport_async]
49
52
50
53
@@ -54,20 +57,17 @@ async def shared_transport_async_with_pooling():
54
57
55
58
conn = aiohttp .TCPConnector (limit = 100 )
56
59
session = aiohttp .ClientSession (connector = conn )
57
- shared_transport = AioHttpTransport (session = session )
60
+ shared_transport = AioHttpTransport (session = session , session_owner = False )
58
61
async with shared_transport :
59
- blob_service_client1 = BlobServiceClient .from_connection_string (
60
- connection_string , transport = shared_transport , session_owner = False
61
- )
62
- blob_service_client2 = BlobServiceClient .from_connection_string (
63
- connection_string , transport = shared_transport , session_owner = False
64
- )
62
+ blob_service_client1 = BlobServiceClient .from_connection_string (connection_string , transport = shared_transport )
63
+ blob_service_client2 = BlobServiceClient .from_connection_string (connection_string , transport = shared_transport )
65
64
containers1 = blob_service_client1 .list_containers ()
66
65
async for contain in containers1 :
67
66
print (contain .name )
68
67
containers2 = blob_service_client2 .list_containers ()
69
68
async for contain in containers2 :
70
69
print (contain .name )
70
+ await session .close () # we need to close the session manually
71
71
# [END shared_transport_async_with_pooling]
72
72
73
73
0 commit comments