Skip to content

Commit 704628b

Browse files
committed
Merge pull request #11923 from AnyISalIn/dev
[bug] If txt2img/img2img raises an exception, finally call state.end()
1 parent 636ff51 commit 704628b

1 file changed

Lines changed: 20 additions & 16 deletions

File tree

‎modules/api/api.py‎

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -333,14 +333,16 @@ def text2imgapi(self, txt2imgreq: models.StableDiffusionTxt2ImgProcessingAPI):
333333
p.outpath_grids = opts.outdir_txt2img_grids
334334
p.outpath_samples = opts.outdir_txt2img_samples
335335

336-
shared.state.begin(job="scripts_txt2img")
337-
if selectable_scripts is not None:
338-
p.script_args = script_args
339-
processed = scripts.scripts_txt2img.run(p, *p.script_args) # Need to pass args as list here
340-
else:
341-
p.script_args = tuple(script_args) # Need to pass args as tuple here
342-
processed = process_images(p)
343-
shared.state.end()
336+
try:
337+
shared.state.begin(job="scripts_txt2img")
338+
if selectable_scripts is not None:
339+
p.script_args = script_args
340+
processed = scripts.scripts_txt2img.run(p, *p.script_args) # Need to pass args as list here
341+
else:
342+
p.script_args = tuple(script_args) # Need to pass args as tuple here
343+
processed = process_images(p)
344+
finally:
345+
shared.state.end()
344346

345347
b64images = list(map(encode_pil_to_base64, processed.images)) if send_images else []
346348

@@ -390,14 +392,16 @@ def img2imgapi(self, img2imgreq: models.StableDiffusionImg2ImgProcessingAPI):
390392
p.outpath_grids = opts.outdir_img2img_grids
391393
p.outpath_samples = opts.outdir_img2img_samples
392394

393-
shared.state.begin(job="scripts_img2img")
394-
if selectable_scripts is not None:
395-
p.script_args = script_args
396-
processed = scripts.scripts_img2img.run(p, *p.script_args) # Need to pass args as list here
397-
else:
398-
p.script_args = tuple(script_args) # Need to pass args as tuple here
399-
processed = process_images(p)
400-
shared.state.end()
395+
try:
396+
shared.state.begin(job="scripts_img2img")
397+
if selectable_scripts is not None:
398+
p.script_args = script_args
399+
processed = scripts.scripts_img2img.run(p, *p.script_args) # Need to pass args as list here
400+
else:
401+
p.script_args = tuple(script_args) # Need to pass args as tuple here
402+
processed = process_images(p)
403+
finally:
404+
shared.state.end()
401405

402406
b64images = list(map(encode_pil_to_base64, processed.images)) if send_images else []
403407

0 commit comments

Comments
 (0)