ai-flow
ai-flow copied to clipboard
[NotificationService] Cannot use one EmbeddedNotificationClient instance in multiple threads
Describe the bug
Cannot use one EmbeddedNotificationClient instance in multiple threads.
Your environment
Operating system
Database
Python version
To Reproduce
def test_create_client_multiple_threads(self):
import threading
from notification_service.embedded_notification_client import EmbeddedNotificationClient
from notification_service.event import Event, EventKey
client = EmbeddedNotificationClient(server_uri="localhost:50052", namespace='default', sender='sender')
def send_event():
event = Event(event_key=EventKey('key1'), message='a')
client.send_event(event)
print(client.sequence_number)
threads = []
for i in range(100):
thread = threading.Thread(target=send_event)
threads.append(thread)
for t in threads:
t.start()
for t in threads:
t.join()
Expected behavior
100 events sent.
Actual behavior
less than 100 events sent.