Skip to content

Commit

Permalink
Switch to asyncio.eager_task_factory for Python 3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
sphuber committed Feb 2, 2024
1 parent 4a8f9b8 commit fead8c5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/kiwipy/rmq/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import asyncio
import collections
from contextlib import asynccontextmanager
from functools import partial
import logging
from typing import Generator, Optional
import uuid
Expand All @@ -20,6 +21,12 @@

TaskInfo = collections.namedtuple('TaskBody', ('task', 'no_reply'))

try:
run_coroutine = asyncio.eager_task_factory
except AttributeError:
# For Python older than 3.12
run_coroutine = asyncio.run_coroutine_threadsafe


class RmqTaskSubscriber(messages.BaseConnectionWithExchange):
"""
Expand Down Expand Up @@ -311,7 +318,7 @@ def _outcome_destroyed(self, outcome_ref):
assert outcome_ref is self._outcome_ref
# This task will not be processed
self._outcome_ref = None
asyncio.run_coroutine_threadsafe(self.requeue(), loop=self._loop)
partial(run_coroutine, loop=self._loop)(coro=self.requeue())

def _finalise(self):
self._outcome_ref = None
Expand Down

0 comments on commit fead8c5

Please sign in to comment.