- Add proper locking using existing _lock mechanism in emit() method
- Add thread safety to register_handler() method
- Add comprehensive thread safety tests for concurrent event emission
- Add tests for concurrent handler registration
- Add tests for mixed concurrent operations
- Fixes issue #2991 where streaming events could get mixed between users
The emit() method now uses the existing _lock to ensure thread-safe access
to the _handlers dictionary and signal emission. This prevents race conditions
that could cause data mixing when multiple users interact with streaming
functionality simultaneously.
Resolves#2991
Co-Authored-By: João <joao@crewai.com>