AWS Thinkbox Discussion Forums

Draft decoder holding onto input even after .FinalizeEncoding() has run

Happy new year draft forum!

Im trying to clean up some temp files , that were used durning an encoding job.
im waiting till after i have run my .FinalizeEncoding(), sleeping for 3 seconds, then trying to remove the tamp incoming file that i passed to the decoder class earlier in the script.

since i see no way to finalise the decoder class, is there something im missing , that would allow me to delete these files. seems like something still has a hold on the file.

the sudo code is:

copy incoming file to local temp.
decoder = Draft.VideoDecoder(file_copied_to_local_temp)
for frame in range:
    do some overlay cool things to current frame
    encoder.EncodeNextFrame(frame)
encoder.FinalizeEncoding()

if temp_folder:
    time.sleep(3)
    shutil.rmtree(temp_folder)

at this point shutil throws a:

The process cannot access the file because it is being used by another process

Any ideas on what could be occuring?

Cheers
kym

Hmm no answers yet.
So rephrasing the question, is there a better way to clean up the files after running draft?

Mmm. It might be that we only clean up the handles when the instance gets destroyed on the C++ side, and Python can choose when to garbage collect it.

Try adding this after FinalizeEncoding:

del encoder

If that doesn’t work, I’ll dive in deeper. I’ll also see if it’s possible for us to clean up on FInalizeEncoding(). It may take a lot of sugar to guard against folks using the object after they call that function.

Update: I just realized, is the the temporary file the input or the output here? The decoder will only close resources when it’s cleaned up, so del decoder is going to be needed there.

Hey @eamsler,

to confirm :

del encoder
del decoder

This solves the issue, the deletion of the temporary folder and files work correctly.

Cheers
Kym

Solid! Thanks for the confirmation. I think this is intended behavior, but the encoder should be thoroughly cleaning up after FinalizeEncoding.

Privacy | Site terms | Cookie preferences