Repository: stable-diffusion-webui
Issue: [Bug]: PermissionError on Windows when replacing the tmp image with the actual png
Labels: bug-report

### Is there an existing issue for this?

- [X] I have searched the existing issues and checked the recent builds/commits

### 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](https://github.com/AUTOMATIC1111/stable-diffusion-webui/files/12653335/sysinfo-2023-09-18-20-35.txt)


### What browsers do you use to access the UI ?

Google Chrome

### Console logs

```Shell
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_