def callback(environ, start_response): try: return _callback(environ, start_response) finally: configFile = environ[CONFIG_FILE_KEY] configName = environ[CONFIG_NAME_KEY] config = Config(configFile, configName) cfg = config.read() store = FileStore(cfg=cfg) # Perform required cleanup task. Given the difficulty of controlling threads # in WSGI having an invocation at the end of the call back is an acceptable trade-off # This might have to be improved later... store.cleanup()