I read your post again, and it looks as though you might want to use the atexit module. Another idea would be to trap the SIGTERM signal and to keep a registry of instances, and then to invoke a cleanup method of each instance. Another important note: trapping signals will have no effect if your process terminates itself. Cheers