Cleanup
Last updated
Last updated
The concept of cleanup after application run time is nothing new, but often ignored or forgotten by developers. What happens during cleanup all depends on the application. This might mean closing and deleting temporary files, removing session data, or deleting a PID (Process ID) file for example.
To allow for application cleanup not only within your program, but also external plugins and extensions, there is the method that must be called after regardless of any exceptions or runtime errors.
Calling ensures that the and framework hooks are run, allowing extensions/plugins/etc to cleanup after the program runs.
You can optionally configure your application to automatically call sys.exit()
as well as set the status code that your application exists with via the meta option as well as setting App.exit_code
:
Note the use of the App.exit_on_close
meta option. Cement will not call sys.exit()
unless this is set to True
. You will find that calling sys.exit()
in testing is very problematic, therefore you will likely want to enable exit_on_close
in production, but not for testing as in this example:
Any extension, or plugin, or even the application itself that has cleanup code should do so within the pre_close
or post_close
framework hooks to ensure that it gets run.