mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-22 14:48:13 +00:00
fix: properly cleanup Rich Live sessions after flow/crew completion
- Add stop_live() method to ConsoleFormatter to clean up Live sessions - Call cleanup in FlowFinishedEvent and CrewKickoffCompletedEvent handlers - Add comprehensive tests for Live session cleanup functionality - Fixes issue #3136 where logging output was suppressed after CrewAI operations The issue was that Rich Live sessions were not being explicitly stopped when CrewAI flows or crews completed, leaving the terminal in a state where subsequent logging output would be suppressed until process exit. This fix ensures that Live sessions are properly cleaned up by: 1. Adding a stop_live() method that safely stops and clears Live sessions 2. Calling this cleanup method in the appropriate event handlers 3. Adding tests to prevent regression Resolves #3136 Co-Authored-By: Jo\u00E3o <joao@crewai.com>
This commit is contained in:
@@ -114,3 +114,38 @@ class TestConsoleFormatterPauseResume:
|
||||
|
||||
assert hasattr(formatter, '_live_paused')
|
||||
assert not formatter._live_paused
|
||||
|
||||
def test_stop_live_with_active_session(self):
|
||||
"""Test stopping Live session when one is active."""
|
||||
formatter = ConsoleFormatter()
|
||||
|
||||
mock_live = MagicMock(spec=Live)
|
||||
formatter._live = mock_live
|
||||
|
||||
formatter.stop_live()
|
||||
|
||||
mock_live.stop.assert_called_once()
|
||||
assert formatter._live is None
|
||||
|
||||
def test_stop_live_with_no_session(self):
|
||||
"""Test stopping Live session when none exists."""
|
||||
formatter = ConsoleFormatter()
|
||||
|
||||
formatter._live = None
|
||||
|
||||
formatter.stop_live()
|
||||
|
||||
assert formatter._live is None
|
||||
|
||||
def test_stop_live_multiple_calls(self):
|
||||
"""Test multiple calls to stop_live are safe."""
|
||||
formatter = ConsoleFormatter()
|
||||
|
||||
mock_live = MagicMock(spec=Live)
|
||||
formatter._live = mock_live
|
||||
|
||||
formatter.stop_live()
|
||||
formatter.stop_live()
|
||||
|
||||
mock_live.stop.assert_called_once()
|
||||
assert formatter._live is None
|
||||
|
||||
Reference in New Issue
Block a user