How can I know when the texture image is completed loaded?

Hi! I’m new to Blender addons. I’m writing an addon that involves the action of downloading an image and then loading the image as an environment and background. However, I do not want to keep the downloaded image on the disk, so I would like to delete the image from the disk after loading as a texture.

Here’s what my code looks like

bg_node = my_node_tree.nodes.new('ShaderNodeBackground')
env_node = my_node_tree.nodes.new('ShaderNodeTexEnvironment')
output_node = my_node_tree.nodes.new('ShaderNodeOutputWorld')

image = bpy.data.images.load(tmp_file_name, check_existing=True)
env_node.image = image

my_node_tree.links.new(env_node.outputs['Color'], bg_node.inputs['Color'])
my_node_tree.links.new(bg_node.outputs['Background'], output_node.inputs['Surface'])

# time.sleep(10)
os.remove(tmp_file_name)

The problem I’m facing right now is that the image file was deleted before the image loading was completed. Running this code above would give me a pink background, with an error message GPUTexture: Blender Texture Not Loaded!. From what I understand, pink background = the image being loading is moved, renamed, or even corrupted(in my case, deleted before loading completed). Also, if I put a long sleep(as the 10s sleep in the comment above), or if I do not remove the file at the end, both would give me the correct result(downloaded image as the background instead of the pink background).

So is there a reliable way to tell if the loading is completed so that I can delete the file?

Thanks!

Then once you’ve accomplished this, how will Blender read the texture from “nowhere” and render it?

1 Like

Not sure what you mean. When you say “this”, do you mean this texture loading action or this session of using Blender(save the .blend file and close Blender)?

If it is the first, this is an unrelated concern to this topic.

If it is the latter, I’ve already made it clear that the deletion is only wanted after the image is loaded, Correct me if I’m wrong here. When I said “loaded” I assumed the file was loaded in the RAM. In that case, Blender should not need to look for the image on the disk. The wait-for-10s example I mentioned in the description also proved that.