faust-streaming / faust

Python Stream Processing. A Faust fork
https://faust-streaming.github.io/faust/
Other
1.66k stars 183 forks source link

Use `loop.create_task()` for agent tasks #598

Closed samtx closed 10 months ago

samtx commented 10 months ago

Description

This fixes a bug where asyncio tasks were created directly with the asyncio.Task() class instead of using loop.create_task() or asyncio.create_task(). The Python documentation specifically says to [not create an asyncio.Task directly](https://docs.python.org/3.8/library/asyncio-task.html#asyncio.Task:~:text=Use%20the%20high%2Dlevel%20asyncio.create_task()%20function%20to%20create%20Tasks%2C%20or%20the%20low%2Dlevel%20loop.create_task()%20or%20ensure_future()%20functions.%20Manual%20instantiation%20of%20Tasks%20is%20discouraged.). Creating the task directly could lead to issues when using alternate event loops like uvloop. The Python abstract event loop has a dedicated loop.set_task_factory method for overriding the function to create the asyncio.Task. An application using a custom asyncio task factory could experience weird, unknown behavior, especially if the agents raise an exception or hang due to blocking code.

codecov[bot] commented 10 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (6588a97) 93.73% compared to head (a95ee93) 93.73%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #598 +/- ## ======================================= Coverage 93.73% 93.73% ======================================= Files 102 102 Lines 11158 11158 Branches 1536 1536 ======================================= Hits 10459 10459 Misses 612 612 Partials 87 87 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

wbarnha commented 10 months ago

Thanks for the PR! Here's to hoping for more stability.