-
Notifications
You must be signed in to change notification settings - Fork 29.5k
add task manager #16570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
add task manager #16570
Conversation
based on https://github.com/lllyasviel/stable-diffusion-webui-forge/blob/main/modules_forge/main_thread.py * classified * this way, gc.collect() will work as intended.
| while True: | ||
| time.sleep(0.01) | ||
| if current_id in self.finished_tasks: | ||
| finished = self.finished_tasks.pop(current_id) | ||
| if finished.exception is not None: | ||
| raise finished.exception | ||
|
|
||
| return finished.result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrap modifications of pending_tasks and access to finished_tasks in self.lock.
| def __init__(self): | ||
| self.lock = threading.Lock() | ||
|
|
||
| def work(self, task): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid memory bloat, optionally limit or expire old entries in finished_tasks
| def main_loop(self): | ||
| self.running = True | ||
| while self.running: | ||
| time.sleep(0.01) | ||
| if len(self.pending_tasks) > 0: | ||
| with self.lock: | ||
| task = self.pending_tasks.pop(0) | ||
|
|
||
| self.work(task) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optionally increase sleep time when no tasks are pending, or use threading.Condition() for efficiency:
based on https://github.com/lllyasviel/stable-diffusion-webui-forge/blob/main/modules_forge/main_thread.py
original author's comment in the source code:
and it's commit:
lllyasviel/stable-diffusion-webui-forge@f06ba8e
from commit message:
all tests have been passed but coverage not work)extracted from PR #16484