[問題] 請問要怎麼寫才能保證一定會做clean up?
請問如果在程式一開始時要求了某些資源
該怎麼寫才能讓這些資源保證能夠在程式結束後被釋放?
本來是使用 atexit module
不過後來發現如果直接關閉 console
atexit 所註冊的 function 不會被執行
google 了一下發現底下這三種情形 atexit function 不會被呼叫
the program dies because of a signal
os._exit() is invoked directly
a Python fatal error is detected (in the interpreter)
這造成了一點小困擾,請問有解決辦法嗎?
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.46.149.214
※ 文章網址: http://www.ptt.cc/bbs/Python/M.1406768736.A.337.html
→
07/31 10:22, , 1F
07/31 10:22, 1F
→
07/31 13:22, , 2F
07/31 13:22, 2F
→
07/31 20:18, , 3F
07/31 20:18, 3F
→
07/31 20:18, , 4F
07/31 20:18, 4F