fix(utils): Fix TypeError in priority_limit_async_func_call when comparing Future objects
This commit is contained in:
@@ -8,7 +8,6 @@ import logging
|
|||||||
import logging.handlers
|
import logging.handlers
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import time
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from hashlib import md5
|
from hashlib import md5
|
||||||
@@ -302,12 +301,13 @@ def priority_limit_async_func_call(max_size: int):
|
|||||||
queue = asyncio.PriorityQueue()
|
queue = asyncio.PriorityQueue()
|
||||||
tasks = set()
|
tasks = set()
|
||||||
lock = asyncio.Lock()
|
lock = asyncio.Lock()
|
||||||
|
counter = 0
|
||||||
|
|
||||||
# Worker function that processes tasks from the queue
|
# Worker function that processes tasks from the queue
|
||||||
async def worker():
|
async def worker():
|
||||||
"""Worker that processes tasks from the priority queue"""
|
"""Worker that processes tasks from the priority queue"""
|
||||||
while True:
|
while True:
|
||||||
# Get task from queue (priority, task_id, future, args, kwargs)
|
# Get task from queue (priority, count, future, args, kwargs)
|
||||||
_, _, future, args, kwargs = await queue.get()
|
_, _, future, args, kwargs = await queue.get()
|
||||||
try:
|
try:
|
||||||
# Execute the function
|
# Execute the function
|
||||||
@@ -360,11 +360,13 @@ def priority_limit_async_func_call(max_size: int):
|
|||||||
# Create future for result
|
# Create future for result
|
||||||
future = asyncio.Future()
|
future = asyncio.Future()
|
||||||
|
|
||||||
# Create unique task ID
|
nonlocal counter
|
||||||
task_id = id(args) + id(kwargs) + id(time.time())
|
async with lock:
|
||||||
|
current_count = counter
|
||||||
|
counter += 1
|
||||||
|
|
||||||
# Put task in queue with priority
|
# Put task in queue with priority and monotonic counter
|
||||||
await queue.put((_priority, task_id, future, args, kwargs))
|
await queue.put((_priority, current_count, future, args, kwargs))
|
||||||
|
|
||||||
# Wait for result with optional timeout
|
# Wait for result with optional timeout
|
||||||
if _timeout is not None:
|
if _timeout is not None:
|
||||||
|
Reference in New Issue
Block a user