()
| 200 | |
| 201 | |
| 202 | def thread_get_next_task(): |
| 203 | from easydiffusion import runtime |
| 204 | |
| 205 | if not manager_lock.acquire(blocking=True, timeout=LOCK_TIMEOUT): |
| 206 | log.warn(f"Render thread on device: {runtime.context.device} failed to acquire manager lock.") |
| 207 | return None |
| 208 | if len(tasks_queue) <= 0: |
| 209 | manager_lock.release() |
| 210 | return None |
| 211 | task = None |
| 212 | try: # Select a render task. |
| 213 | for queued_task in tasks_queue: |
| 214 | if queued_task.render_device and runtime.context.device != queued_task.render_device: |
| 215 | # Is asking for a specific render device. |
| 216 | if is_alive(queued_task.render_device) > 0: |
| 217 | continue # requested device alive, skip current one. |
| 218 | else: |
| 219 | # Requested device is not active, return error to UI. |
| 220 | queued_task.error = Exception(queued_task.render_device + " is not currently active.") |
| 221 | task = queued_task |
| 222 | break |
| 223 | if not queued_task.render_device and runtime.context.device == "cpu" and is_alive() > 1: |
| 224 | # not asking for any specific devices, cpu want to grab task but other render devices are alive. |
| 225 | continue # Skip Tasks, don't run on CPU unless there is nothing else or user asked for it. |
| 226 | task = queued_task |
| 227 | break |
| 228 | if task is not None: |
| 229 | del tasks_queue[tasks_queue.index(task)] |
| 230 | return task |
| 231 | finally: |
| 232 | manager_lock.release() |
| 233 | |
| 234 | |
| 235 | def thread_render(device): |
no test coverage detected