# -*- coding: utf-8 -*- import atexit def close(): print('close') # 注册方式一 atexit.register(close) # 注册方式二 @atexit.register def close_file(): print('close_file')
输出顺序
close_file close
# -*- coding: utf-8 -*- import atexit def close(): print('close') # 注册方式一 atexit.register(close) # 注册方式二 @atexit.register def close_file(): print('close_file')
输出顺序
close_file close