Better handling of temp files #39690

Closed
opened 2014-04-12 16:42:22 +02:00 by Bastien Montagne · 8 comments

Right now, Blender just stores its temp files in temp directory. In some cases, it even uses PID to avoid several instances of it using the same files (at least, for point caches of unsaved .blends, and added that behavior to fix #39521, see 6cd717e0a3).

The issue is that Blender never removes those files, and some OSs (Windows…) never clean up their temp dir, which can leads to a quick waste of space. So here is the proposition (also from discussion with Campbell):

  • At startup, Blender creates a (PID-tagged) folder in temp dir, where it stores all files that are really temp ones.
  • When closing, Blender removes that folder and all its content.

For the very few cases where we need a 'cross-session' persistent 'temp' files (only render result afaik?), we could create temp file directly in main tmp dir (not in Blender session’s PID-tagged one).

The issue here is how to avoid several instances to use the same 'persistent' file? We could use locks, but I can’t find a nice way to handle them (main issue being to handle crashes, which are one key reason to have those persistent render results). Or maybe we just decide this is a corner case we do not want to support (i.e. in situations like #39521, we simply accept both processes write the same temp render result file - intermediate samples being saved in PID temp folder anyway)?

Right now, Blender just stores its temp files in temp directory. In some cases, it even uses PID to avoid several instances of it using the same files (at least, for point caches of unsaved .blends, and added that behavior to fix #39521, see 6cd717e0a3). The issue is that Blender never removes those files, and some OSs (Windows…) never clean up their temp dir, which can leads to a quick waste of space. So here is the proposition (also from discussion with Campbell): * At startup, Blender creates a (PID-tagged) folder in temp dir, where it stores all files that are really temp ones. * When closing, Blender removes that folder and all its content. For the very few cases where we need a 'cross-session' persistent 'temp' files (only render result afaik?), we could create temp file directly in main tmp dir (**not** in Blender session’s PID-tagged one). The issue here is how to avoid several instances to use the same 'persistent' file? We could use locks, but I can’t find a nice way to handle them (main issue being to handle crashes, which are one key reason to have those persistent render results). Or maybe we just decide this is a corner case we do not want to support (i.e. in situations like #39521, we simply accept both processes write the same temp render result file - intermediate samples being saved in PID temp folder anyway)?
Author
Owner

Changed status to: 'Open'

Changed status to: 'Open'
Author
Owner

Added subscribers: @mont29, @ideasman42, @brecht, @Sergey

Added subscribers: @mont29, @ideasman42, @brecht, @Sergey

I suggest to look at what other applications do, this must be a common problem. There also exist operating system functions like mktemp to get unique filenames, which I think we should use when possible rather than creating our own system with PIDs.

One case to think of as well is crashes, you don't want all the temp files to stick around when Blender crashes.

For the render result we should make the caching an option I think, that is disabled by default. Not sure about the best location for the file, maybe the output file path. It can still create a temp file if the caching is disabled.

I suggest to look at what other applications do, this must be a common problem. There also exist operating system functions like `mktemp` to get unique filenames, which I think we should use when possible rather than creating our own system with PIDs. One case to think of as well is crashes, you don't want all the temp files to stick around when Blender crashes. For the render result we should make the caching an option I think, that is disabled by default. Not sure about the best location for the file, maybe the output file path. It can still create a temp file if the caching is disabled.

I'm not so much fun of this PID and mktemp things actually.

Not sure what else apart from the saved buffers gives issues, but for saved buffers it'll be better idea to NOT use PID but use full .blend file path converted to a proper file name (i.e. /home/sergey/blah.blend becomes /tmp/home_sergey_blah.blend). This way it'll be still possible to restart blender and use render buffers from the previous instance.

Just an idea, if we wouldn't find it's suitable then i'll fine with the PID salt or mktemp. Maybe mktemp is the better approach in fact.

I'm not so much fun of this PID and mktemp things actually. Not sure what else apart from the saved buffers gives issues, but for saved buffers it'll be better idea to NOT use PID but use full .blend file path converted to a proper file name (i.e. /home/sergey/blah.blend becomes /tmp/home_sergey_blah.blend). This way it'll be still possible to restart blender and use render buffers from the previous instance. Just an idea, if we wouldn't find it's suitable then i'll fine with the PID salt or mktemp. Maybe mktemp is the better approach in fact.
Bastien Montagne self-assigned this 2014-04-17 14:15:44 +02:00
Author
Owner

Not sure what else apart from the saved buffers gives issues, but for saved buffers it'll be better idea to NOT use PID but use full .blend file path converted to a proper file name (i.e. /home/sergey/blah.blend becomes /tmp/home_sergey_blah.blend). This way it'll be still possible to restart blender and use render buffers from the previous instance.

That’s already what is done, but this fails when you render the same frames of the same file in two different processes (like in org BT, where the only diff was the used cameras).

For the render result we should make the caching an option I think, that is disabled by default. Not sure about the best location for the file, maybe the output file path. It can still create a temp file if the caching is disabled.

Agree, current situation is a bit like bug-that-becomes-a-feature…

One case to think of as well is crashes, you don't want all the temp files to stick around when Blender crashes.

Yes, this is the main issue, yet have to check whether our crash handler (the one writing crash log) would be able to also delete temp files (hopefully it will ;) ).

> Not sure what else apart from the saved buffers gives issues, but for saved buffers it'll be better idea to NOT use PID but use full .blend file path converted to a proper file name (i.e. /home/sergey/blah.blend becomes /tmp/home_sergey_blah.blend). This way it'll be still possible to restart blender and use render buffers from the previous instance. That’s already what is done, but this fails when you render *the same frames of the same file* in two different processes (like in org BT, where the only diff was the used cameras). > For the render result we should make the caching an option I think, that is disabled by default. Not sure about the best location for the file, maybe the output file path. It can still create a temp file if the caching is disabled. Agree, current situation is a bit like bug-that-becomes-a-feature… > One case to think of as well is crashes, you don't want all the temp files to stick around when Blender crashes. Yes, this is the main issue, yet have to check whether our crash handler (the one writing crash log) would be able to also delete temp files (hopefully it will ;) ).

Added subscriber: @drekryan

Added subscriber: @drekryan
Author
Owner

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'
Author
Owner

Applied D531 as 414c70435d.

Applied [D531](https://archive.blender.org/developer/D531) as 414c70435d.
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#39690
No description provided.