Skip to content

Commit

Permalink
preview use per-job lock instead of global
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Mandic <[email protected]>
  • Loading branch information
vladmandic committed Dec 31, 2024
1 parent 8f35f09 commit c201695
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion modules/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def progressapi(req: ProgressRequest):
id_live_preview = req.id_live_preview
live_preview = None
updated = shared.state.set_current_image()
debug_log(f'Preview: job={shared.state.job} active={active} progress={current}/{total} step={shared.state.current_image_sampling_step}/{shared.state.sampling_step} request={id_live_preview} last={shared.state.id_live_preview} enabled={shared.opts.live_previews_enable} busy={shared.state.preview_busy} updated={updated} image={shared.state.current_image} elapsed={elapsed:.3f}')
debug_log(f'Preview: job={shared.state.job} active={active} progress={current}/{total} step={shared.state.current_image_sampling_step}/{shared.state.sampling_step} request={id_live_preview} last={shared.state.id_live_preview} enabled={shared.opts.live_previews_enable} job={shared.state.preview_job} updated={updated} image={shared.state.current_image} elapsed={elapsed:.3f}')
if not active:
return InternalProgressResponse(job=shared.state.job, active=active, queued=queued, paused=paused, completed=completed, id_live_preview=-1, debug=debug, textinfo="Queued..." if queued else "Waiting...")
if shared.opts.live_previews_enable and (shared.state.id_live_preview != id_live_preview) and (shared.state.current_image is not None):
Expand Down
18 changes: 7 additions & 11 deletions modules/shared_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class State:
prediction_type = "epsilon"
api = False
disable_preview = False
preview_busy = False
preview_job = -1
time_start = None
need_restart = False
server_start = time.time()
Expand Down Expand Up @@ -113,7 +113,7 @@ def begin(self, title="", api=None):
self.current_sigma_next = None
self.id_live_preview = 0
self.interrupted = False
self.preview_busy = False
self.preview_job = -1
self.job = title
self.job_count = -1
self.frame_count = -1
Expand All @@ -136,15 +136,11 @@ def end(self, api=None):
# fn = f'{sys._getframe(2).f_code.co_name}:{sys._getframe(1).f_code.co_name}' # pylint: disable=protected-access
# log.debug(f'Access state.end: {fn}') # pylint: disable=protected-access
self.time_start = time.time()
if self.debug_output:
if self.preview_busy:
log.debug('State end: preview busy')
log.debug(f'State end: {self.job} time={time.time() - self.time_start:.2f}')
self.job = ""
self.job_count = 0
self.job_no = 0
self.frame_count = 0
self.preview_busy = False
self.preview_job = -1
self.paused = False
self.interrupted = False
self.skipped = False
Expand All @@ -162,10 +158,10 @@ def set_current_image(self):
return False

def do_set_current_image(self):
if (self.current_latent is None) or self.disable_preview or self.preview_busy:
if (self.current_latent is None) or self.disable_preview or (self.preview_job == self.job_no):
return False
from modules import shared, sd_samplers
self.preview_busy = True
self.preview_job = self.job_no
try:
sample = self.current_latent
self.current_image_sampling_step = self.sampling_step
Expand All @@ -180,10 +176,10 @@ def do_set_current_image(self):
pass # ignore sigma errors
image = sd_samplers.samples_to_image_grid(sample) if shared.opts.show_progress_grid else sd_samplers.sample_to_image(sample)
self.assign_current_image(image)
self.preview_busy = False
self.preview_job = -1
return True
except Exception as e:
self.preview_busy = False
self.preview_job = -1
log.error(f'State image: last={self.id_live_preview} step={self.sampling_step} {e}')
display(e, 'State image')
return False
Expand Down
2 changes: 1 addition & 1 deletion wiki
Submodule wiki updated from 9eaaec to 9f132c

0 comments on commit c201695

Please sign in to comment.