clean()
function to help you remove temporary files and folders after processing. This guide will show you how to use this cleanup utility effectively.
The clean() Function
Theclean()
function is part of Runpod’s serverless utilities. It helps maintain a clean environment by removing specified folders and files after a job is completed.
To use it, import the function from the Runpod serverless utilities:
Default Behavior
By default,clean()
removes the following:
input_objects
folderoutput_objects
folderjob_files
folderoutput.zip
file
Using clean() in Your Handler
Here’s an example of how to incorporate theclean()
function in your AI model handler:
clean()
is called after the model processing is complete, ensuring that temporary files and folders are removed.
Custom Cleanup
You can also specify additional folders to be removed by passing a list to theclean()
function:
Testing your Handler with Cleanup
To test your handler with the cleanup function:Best Practices
- Call
clean()
at the end of your handler to ensure proper cleanup. - Use try-except blocks to handle any errors during cleanup.
- Be cautious when adding custom folders to the cleanup list.
- Consider logging cleanup actions for debugging purposes.
clean()
function in your handlers, you ensure that each job starts with a clean slate, preventing potential issues caused by leftover files from previous runs.