作者hsnu114444 (littleq0903)
看板Python
標題Re: [問題] Python Module 的 finalizer
時間Fri Feb 7 15:04:48 2014
原文 GC 掉。
---
Python 的 module 從 import 進來就會一直待在 runtime,一直到你做掉 process 爲止
所以你可以透過 atexit 來 register 一個 function,告訴 python 等這個模組被做掉
的時候應該要做什麼事情,用法如下:
```
import atexit
atexit.register(your_function)
```
當這個 module 被關掉的時候,你 register 的 function 就會被呼叫,可以在這中間做
一些類似 GC 的東西。
(我來騙 P 幣的 :P)
--
{
name:
"LittleQ",
title: [
"student",
"software developer"],
languages: [
"English",
"Chinese",
"Python",
"JavaScript",
"Erlang"]
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.34.17.61
推 Wush978:謝謝gc 02/07 15:07
推 keitheis:gc 02/11 22:22
→ hsnu114444:推文爲什麼都在 gc 02/12 12:49
→ hsnu114444:XDDD 02/12 12:49