Skip to content

Commit

Permalink
Eagerly start notification processing with Python 3.12+ (#212)
Browse files Browse the repository at this point in the history
* Eagerly start notification processing with Python 3.12+

* Add to CHANGELOG.md
  • Loading branch information
Pliner authored Sep 1, 2024
1 parent 4ce092a commit 1465bd9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* [Implement metrics/tracing on top of OpenTelemetry](https://github.com/anna-money/asyncpg-listen/pull/199)
* [Support python 3.12 and end support of 3.8](https://github.com/anna-money/asyncpg-listen/pull/211)
* [Eagerly start notification processing with Python 3.12+](https://github.com/anna-money/asyncpg-listen/pull/212)


## v0.0.6 (2022-11-02)
Expand Down
13 changes: 8 additions & 5 deletions asyncpg_listen/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,15 @@ async def _process_notifications(
if notification is None:
continue

# to have independent async context per run
# to protect from misuse of contextvars
try:
await asyncio.create_task(
self._process_notification(handler, notification), name=f"{__package__}.{channel}"
)
# to have independent async context per run
# to protect from misuse of contextvars
coro = self._process_notification(handler, notification)
if sys.version_info >= (3, 12):
task = asyncio.Task(coro, eager_start=True, name=f"{__package__}.{channel}")
else:
task = asyncio.create_task(coro, name=f"{__package__}.{channel}")
await task
except Exception:
logger.exception("Failed to handle %s", notification)

Expand Down

0 comments on commit 1465bd9

Please sign in to comment.