AUTOMATIC1111 / stable-diffusion-webui

Stable Diffusion web UI
GNU Affero General Public License v3.0
140.57k stars 26.6k forks source link

[Bug]: PermissionError on Windows when replacing the tmp image with the actual png #13318

Open KodeKooker opened 1 year ago

KodeKooker commented 1 year ago

Is there an existing issue for this?

What happened?

The saving of the image failed with an error inside the console, and the batch generation was aborted. This issue seems to be randomic, not always reproducible.

Note: the "--listen" batch parameter is set and the batch is generated from a remote device.

Steps to reproduce the problem

  1. Go to txt2img tab of the web interface from a remote device
  2. Press generate with any prompt, set batch count to 4 or 5
  3. look at the console output, sometimes the error will be reproduced

What should have happened?

The batch generation should finish without errors.

Sysinfo

sysinfo-2023-09-18-20-35.txt

What browsers do you use to access the UI ?

Google Chrome

Console logs

Traceback:

  File "C:\Users\MyUser\stable-diffusion-webui-ok\stable-diffusion-webui\modules\call_queue.py", line 57, in f
        res = list(func(*args, **kwargs))
      File "C:\Users\MyUser\stable-diffusion-webui-ok\stable-diffusion-webui\modules\call_queue.py", line 36, in f
        res = func(*args, **kwargs)
      File "C:\Users\MyUser\stable-diffusion-webui-ok\stable-diffusion-webui\modules\txt2img.py", line 55, in txt2img
        processed = processing.process_images(p)
      File "C:\Users\MyUser\stable-diffusion-webui-ok\stable-diffusion-webui\modules\processing.py", line 732, in process_images
        res = process_images_inner(p)
      File "C:\Users\MyUser\stable-diffusion-webui-ok\stable-diffusion-webui\extensions\sd-webui-controlnet\scripts\batch_hijack.py", line 42, in processing_process_images_hijack
        return getattr(processing, '__controlnet_original_process_images_inner')(p, *args, **kwargs)
      File "C:\Users\MyUser\stable-diffusion-webui-ok\stable-diffusion-webui\modules\processing.py", line 932, in process_images_inner
        images.save_image(image, p.outpath_samples, "", p.seeds[i], p.prompts[i], opts.samples_format, info=infotext(i), p=p)
      File "C:\Users\MyUser\stable-diffusion-webui-ok\stable-diffusion-webui\modules\images.py", line 672, in save_image
        _atomically_save_image(image, fullfn_without_extension, extension)
      File "C:\Users\MyUser\stable-diffusion-webui-ok\stable-diffusion-webui\modules\images.py", line 664, in _atomically_save_image
        os.replace(temp_file_path, filename_without_extension + extension)
    PermissionError: [WinError 32] Impossibile accedere al file. Il file è utilizzato da un altro processo: 'E:/Immagini/stablediff-output/txt2img-images\\2023-09-17\\00000-1427175482.tmp' -> 'E:/Immagini/stablediff-output/txt2img-images\\2023-09-17\\00000-1427175482.png'

Additional information

A workaround is to retry the "os.replace" after a short amount of time, until it doesn't throw the exception anymore. It seems that on windows the temporary file is still in use when the script tries to rename it into the final png image.

No response

tartarengia commented 12 months ago

same error with doing batching. error happen everytime. with this error code: stable diffusion permissionerror: [winerror 32] the process cannot access the file because it is being used by another process: