Skip to content

Commit c5e214c

Browse files
authored
dynamic_async: Add breakpoint for when a job is cancelled (#551)
Previously, when the job cancel function was called, the job itself wasn't notified that it's cancelled. This caused a deadlock in the calling function due to waiting forever in a queue. Therefore, add a signal to break out of the generation loop on a call to cancel. Signed-off-by: kingbri <[email protected]>
1 parent 3ffcc74 commit c5e214c

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

exllamav2/generator/dynamic_async.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class ExLlamaV2DynamicJobAsync:
7575
job: ExLlamaV2DynamicJob
7676
queue: asyncio.Queue
7777
generator: ExLlamaV2DynamicGeneratorAsync
78+
cancelled: bool = False
7879

7980
def __init__(self, generator: ExLlamaV2DynamicGeneratorAsync, *args: object, **kwargs: object):
8081
self.generator = generator
@@ -87,6 +88,10 @@ async def put_result(self, result):
8788

8889
async def __aiter__(self):
8990
while True:
91+
# Get out if the job is cancelled
92+
if self.cancelled:
93+
break
94+
9095
result = await self.queue.get()
9196
if isinstance(result, Exception):
9297
raise result
@@ -96,3 +101,4 @@ async def __aiter__(self):
96101

97102
async def cancel(self):
98103
await self.generator.cancel(self)
104+
self.cancelled = True

0 commit comments

Comments
 (0)