Skip to content

Commit

Permalink
Clear earlier unfinished jobs from history when a job completes #814
Browse files Browse the repository at this point in the history
those are likely zombies that were interrupted or never scheduled due to server disconnect
  • Loading branch information
Acly committed Jul 12, 2024
1 parent 712918a commit 8578728
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ai_diffusion/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Generative AI plugin for Krita using Stable Diffusion"""

__version__ = "1.20.0"
__version__ = "1.20.1"

import importlib.util

Expand Down
11 changes: 11 additions & 0 deletions ai_diffusion/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,12 @@ def notify_started(self, job: Job):
def notify_finished(self, job: Job):
job.state = JobState.finished
self.job_finished.emit(job)
self._cancel_earlier_jobs(job)
self.count_changed.emit()

def notify_cancelled(self, job: Job):
job.state = JobState.cancelled
self._cancel_earlier_jobs(job)
self.count_changed.emit()

def notify_used(self, job_id: str, index: int):
Expand Down Expand Up @@ -225,3 +227,12 @@ def selection(self, value: Item | None):
@property
def memory_usage(self):
return self._memory_usage

def _cancel_earlier_jobs(self, job: Job):
# Clear jobs that should have been completed before, but may not have completed
# (still queued or executing state) due to sporadic server disconnect
for j in self._entries:
if j is job:
break
if j.state in [JobState.queued, JobState.executing]:
j.state = JobState.cancelled

0 comments on commit 8578728

Please sign in to comment.