作者os653 (allstar)
看板Python
標題[問題] 請問要怎麼寫才能保證一定會做clean up?
時間Thu Jul 31 09:05:33 2014
請問如果在程式一開始時要求了某些資源
該怎麼寫才能讓這些資源保證能夠在程式結束後被釋放?
本來是使用 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
→ uranusjr:沒有 07/31 10:22
→ carylorrk:程式結束後 resource 不是應該被 OS release 嗎? 07/31 13:22
→ os653:我只知道像記憶體之類的會被release,其他有很多不確定 07/31 20:18
→ os653:既然沒有解決辦法,就只好假裝沒看到了 冏rz... 07/31 20:18