The latter is only possible as we dropped support for Python 3.7.
ALock = asyncio.Lock
+def current_thread_name() -> str:
+ return threading.current_thread().name
+
+
+def current_task_name() -> str:
+ t = asyncio.current_task()
+ return t.get_name() if t else "<no task>"
+
+
class Queue(queue.Queue[T]):
"""
A Queue subclass with an interruptible get() method.
from .errors import PoolClosed, PoolTimeout, TooManyRequests
from ._compat import Deque
from ._acompat import Condition, Event, Lock, Queue, spawn, gather
+from ._acompat import current_thread_name
logger = logging.getLogger("psycopg.pool")
task = q.get()
if isinstance(task, StopWorker):
- logger.debug(
- "terminating working thread %s", threading.current_thread().name
- )
+ logger.debug("terminating working thread %s", current_thread_name())
return
# Run the task. Make sure don't die in the attempt.
logger.debug("task run discarded: %s", self)
return
- logger.debug("task running in %s: %s", threading.current_thread().name, self)
+ logger.debug("task running in %s: %s", current_thread_name(), self)
self._run(pool)
def tick(self) -> None:
from .errors import PoolClosed, PoolTimeout, TooManyRequests
from ._compat import Deque
from ._acompat import ACondition, AEvent, ALock, AQueue, aspawn, agather
+from ._acompat import current_task_name
from .sched_async import AsyncScheduler
logger = logging.getLogger("psycopg.pool")
task = await q.get()
if isinstance(task, StopWorker):
- logger.debug("terminating working task")
+ logger.debug("terminating working task %s", current_task_name())
return
# Run the task. Make sure don't die in the attempt.
logger.debug("task run discarded: %s", self)
return
+ logger.debug("task running in %s: %s", current_task_name(), self)
await self._run(pool)
async def tick(self) -> None: