作者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
1F:推 Wush978:谢谢gc 02/07 15:07
2F:推 keitheis:gc 02/11 22:22
3F:→ hsnu114444:推文爲什麽都在 gc 02/12 12:49
4F:→ hsnu114444:XDDD 02/12 12:49