ai-flow icon indicating copy to clipboard operation
ai-flow copied to clipboard

[NotificationService] Cannot use one EmbeddedNotificationClient instance in multiple threads

Open jiangxin369 opened this issue 2 years ago • 0 comments

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.

Screenshots

Additional context

jiangxin369 avatar Jul 11 '22 07:07 jiangxin369