Skip to content

Commit 6a69430

Browse files
authored
[EventHubs & ServiceBus] Async sample should use asyncio.run (Azure#22307)
1 parent 77b3e8f commit 6a69430

30 files changed

+49
-73
lines changed

sdk/eventhub/azure-eventhub/samples/async_samples/client_creation_async.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,5 @@ async def create_consumer_client():
9797
print("Calling consumer client get eventhub properties:", await consumer_client.get_eventhub_properties())
9898

9999

100-
loop = asyncio.get_event_loop()
101-
loop.run_until_complete(create_producer_client())
102-
loop.run_until_complete(create_consumer_client())
100+
asyncio.run(create_producer_client())
101+
asyncio.run(create_consumer_client())

sdk/eventhub/azure-eventhub/samples/async_samples/connection_to_custom_endpoint_address_async.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,5 @@ async def consumer_connecting_to_custom_endpoint():
7070
print('Stopped receiving.')
7171

7272

73-
loop = asyncio.get_event_loop()
74-
loop.run_until_complete(producer_connecting_to_custom_endpoint())
75-
loop.run_until_complete(consumer_connecting_to_custom_endpoint())
73+
asyncio.run(producer_connecting_to_custom_endpoint())
74+
asyncio.run(consumer_connecting_to_custom_endpoint())

sdk/eventhub/azure-eventhub/samples/async_samples/sample_code_eventhub_async.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,6 @@ async def on_event(partition_context, event):
207207
# [END eventhub_consumer_client_close_async]
208208

209209
if __name__ == '__main__':
210-
loop = asyncio.get_event_loop()
211-
# loop.run_until_complete(example_eventhub_async_consumer_receive_and_close())
212-
# loop.run_until_complete(example_eventhub_async_producer_send_and_close())
213-
loop.run_until_complete(example_eventhub_async_send_and_receive())
214-
210+
asyncio.run(example_eventhub_async_consumer_receive_and_close())
211+
asyncio.run(example_eventhub_async_producer_send_and_close())
212+
asyncio.run(example_eventhub_async_send_and_receive())

sdk/eventhub/azure-eventhub/samples/sync_samples/sample_code_eventhub.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,6 @@ def on_event(partition_context, event):
221221

222222

223223
if __name__ == '__main__':
224+
example_eventhub_producer_send_and_close()
225+
example_eventhub_consumer_receive_and_close()
224226
example_eventhub_sync_send_and_receive()
225-
# example_eventhub_producer_send_and_close()
226-
# example_eventhub_consumer_receive_and_close()

sdk/servicebus/azure-servicebus/samples/async_samples/authenticate_client_connstr_async.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,4 @@ async def run():
3232
async with ServiceBusClient.from_connection_string(connstr) as client:
3333
pass # Client is now initialized and can be used.
3434

35-
loop = asyncio.get_event_loop()
36-
loop.run_until_complete(run())
35+
asyncio.run(run())

sdk/servicebus/azure-servicebus/samples/async_samples/authenticate_using_azure_named_key_credential_async.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,4 @@ async def send_message():
2828
async with client.get_queue_sender(QUEUE_NAME) as sender:
2929
await sender.send_messages([ServiceBusMessage("hello")])
3030

31-
loop = asyncio.get_event_loop()
32-
loop.run_until_complete(send_message())
31+
asyncio.run(send_message())

sdk/servicebus/azure-servicebus/samples/async_samples/authenticate_using_azure_sas_credential_async.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,5 @@ async def send_message():
5252
await sender.send_messages([ServiceBusMessage("hello")])
5353

5454

55-
loop = asyncio.get_event_loop()
5655
start_time = time.time()
57-
loop.run_until_complete(send_message())
56+
asyncio.run(send_message())

sdk/servicebus/azure-servicebus/samples/async_samples/auto_lock_renew_async.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ async def on_lock_renew_failure_callback(renewable, error):
127127
print('Lock renew failure demonstration complete.')
128128

129129

130-
131-
loop = asyncio.get_event_loop()
132-
loop.run_until_complete(renew_lock_on_message_received_from_non_sessionful_entity())
133-
loop.run_until_complete(renew_lock_on_session_of_the_sessionful_entity())
134-
loop.run_until_complete(renew_lock_with_lock_renewal_failure_callback())
130+
asyncio.run(renew_lock_on_message_received_from_non_sessionful_entity())
131+
asyncio.run(renew_lock_on_session_of_the_sessionful_entity())
132+
asyncio.run(renew_lock_with_lock_renewal_failure_callback())

sdk/servicebus/azure-servicebus/samples/async_samples/client_identity_authentication_async.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ async def run():
6060

6161
await credential.close()
6262

63-
loop = asyncio.get_event_loop()
64-
loop.run_until_complete(run())
65-
63+
asyncio.run(run())
6664

6765
print("Send message is done.")

sdk/servicebus/azure-servicebus/samples/async_samples/deadletter_messages_and_correct_async.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,4 @@ async def main():
114114

115115
await servicebus_client.close()
116116

117-
loop = asyncio.get_event_loop()
118-
loop.run_until_complete(main())
117+
asyncio.run(main())

0 commit comments

Comments
 (0)