Skip to content

Commit a5a177f

Browse files
Copilotswathipil
andcommitted
Address final review comments: update ServiceBus thread safety wording and remove main functions from README snippets
Co-authored-by: swathipil <[email protected]>
1 parent e38580b commit a5a177f

File tree

1 file changed

+16
-24
lines changed

1 file changed

+16
-24
lines changed

sdk/servicebus/azure-servicebus/README.md

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ To interact with these resources, one should be familiar with the following SDK
9595

9696
### Thread safety
9797

98-
We do not guarantee that the ServiceBusClient, ServiceBusSender, and ServiceBusReceiver are thread-safe or coroutine-safe. We do not recommend reusing these instances across threads or sharing them between coroutines. It is up to the running application to use these classes in a thread-safe manner.
98+
We do not guarantee that the ServiceBusClient, ServiceBusSender, and ServiceBusReceiver are thread-safe or coroutine-safe. We do not recommend reusing these instances across threads or sharing them between coroutines. It is up to the running application to use these classes in a concurrency-safe manner.
9999

100100
The data model type, `ServiceBusMessageBatch` is not thread-safe or coroutine-safe. It should not be shared across threads nor used concurrently with client methods.
101101

@@ -117,19 +117,15 @@ def send_batch(sender_id, sender):
117117
sender.send_messages(messages)
118118
print(f"Sender {sender_id} sent messages.")
119119

120-
def main():
121-
credential = DefaultAzureCredential()
122-
client = ServiceBusClient(fully_qualified_namespace=SERVICE_BUS_NAMESPACE, credential=credential)
123-
124-
with client:
125-
sender = client.get_queue_sender(queue_name=QUEUE_NAME)
126-
with sender:
127-
with ThreadPoolExecutor(max_workers=5) as executor:
128-
for i in range(5):
129-
executor.submit(send_batch, i, sender)
130-
131-
if __name__ == "__main__":
132-
main()
120+
credential = DefaultAzureCredential()
121+
client = ServiceBusClient(fully_qualified_namespace=SERVICE_BUS_NAMESPACE, credential=credential)
122+
123+
with client:
124+
sender = client.get_queue_sender(queue_name=QUEUE_NAME)
125+
with sender:
126+
with ThreadPoolExecutor(max_workers=5) as executor:
127+
for i in range(5):
128+
executor.submit(send_batch, i, sender)
133129
```
134130

135131
For scenarios requiring concurrent sending in asyncio applications, ensure proper coroutine-safety management using mechanisms like asyncio.Lock()
@@ -150,17 +146,13 @@ async def send_batch(sender_id, sender):
150146
await sender.send_messages(messages)
151147
print(f"Sender {sender_id} sent messages.")
152148

153-
async def main():
154-
credential = DefaultAzureCredential()
155-
client = ServiceBusClient(fully_qualified_namespace=SERVICE_BUS_NAMESPACE, credential=credential)
156-
157-
async with client:
158-
sender = client.get_queue_sender(queue_name=QUEUE_NAME)
159-
async with sender:
160-
await asyncio.gather(*(send_batch(i, sender) for i in range(5)))
149+
credential = DefaultAzureCredential()
150+
client = ServiceBusClient(fully_qualified_namespace=SERVICE_BUS_NAMESPACE, credential=credential)
161151

162-
if __name__ == "__main__":
163-
asyncio.run(main())
152+
async with client:
153+
sender = client.get_queue_sender(queue_name=QUEUE_NAME)
154+
async with sender:
155+
await asyncio.gather(*(send_batch(i, sender) for i in range(5)))
164156
```
165157

166158
## Examples

0 commit comments

Comments
 (0)