AUTOMATIC1111 / stable-diffusion-webui

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

[Bug]: Temporary files are not cleaned up #11008

Open allo- opened 1 year ago

allo- commented 1 year ago

Is there an existing issue for this?

What happened?

When generating an image, the webui writes it to /tmp/tmpXXXX.png. It seems that these temporary files are never cleaned up if you don't remove them manually.

Steps to reproduce the problem

  1. Generate an image

What should have happened?

When the image is not displayed anywhere in the UI anymore the temporary file should be deleted. When stopping the UI the files should also be cleaned up. The ui could also use a subfolder for its temporary files, so they are easier to separate from tempfiles of other programs.

Commit where the problem happens

b6af0a3809ea869fb180633f9affcae4b199ffcf

What Python version are you running on ?

Python 3.10.x

What platforms do you use to access the UI ?

Linux

Command Line Arguments

No
AlUlkesh commented 1 year ago

Have you tried these settings?

image

allo- commented 1 year ago

I didn't change the defaults. Under Linux it uses /tmp/tmpXXXXX.png which probably is created by some mktemp equivalent, but it doesn't clean up the files afterward.

The checkbox reads like it is only required when using a custom temp folder?

AlUlkesh commented 1 year ago

Yes, I think if you want the cleanup function, you should set a custom directory and then tick the checkbox.

allo- commented 1 year ago

I would consider it a bug, when the program doesn't remove its temporary files after they are no longer needed, especially when they are in a system-wide temp directory where the user doesn't know that the program leaves them behind. Depending on the system (e.g. if it has a tmpfs mounted at /tmp or not) the folder may fill up with many files that were not even saved.

What about adding an atexit hook that deletes the files generated during a session? Crashes would still leave temp files behind, but that's true for most other programs as well.

The best solution would be when the files are deleted as soon as they are no longer needed, but I see the problem of not knowing if the users still has pages open that show the image and may decide to save them from the browser.