锘??xml version="1.0" encoding="utf-8" standalone="yes"?>在线电影你懂的亚洲,亚洲av成人中文无码专区,亚洲av无码成人精品国产 http://www.tkk7.com/yglwxl/category/39566.htmlzh-cnMon, 30 Nov 2009 11:11:11 GMTMon, 30 Nov 2009 11:11:11 GMT60How does Python manage memory?(http://docs.python.org/3.1/faq/design.html)http://www.tkk7.com/yglwxl/archive/2009/11/30/304232.html涔?jié)瀹?/dc:creator>涔?jié)瀹?/author>Mon, 30 Nov 2009 03:01:00 GMThttp://www.tkk7.com/yglwxl/archive/2009/11/30/304232.htmlhttp://www.tkk7.com/yglwxl/comments/304232.htmlhttp://www.tkk7.com/yglwxl/archive/2009/11/30/304232.html#Feedback0http://www.tkk7.com/yglwxl/comments/commentRss/304232.htmlhttp://www.tkk7.com/yglwxl/services/trackbacks/304232.htmlThe details of Python memory management depend on the implementation. The standard C implementation of Python uses reference counting to detect inaccessible objects, and another mechanism to collect reference cycles, periodically executing a cycle detection algorithm which looks for inaccessible cycles and deletes the objects involved. The gc module provides functions to perform a garbage collection, obtain debugging statistics, and tune the collector’s parameters.

Jython relies on the Java runtime so the JVM’s garbage collector is used. This difference can cause some subtle porting problems if your Python code depends on the behavior of the reference counting implementation.

Sometimes objects get stuck in tracebacks temporarily and hence are not deallocated when you might expect. Clear the tracebacks with:

import sys
sys.exc_clear()
sys.exc_traceback = sys.last_traceback = None

Tracebacks are used for reporting errors, implementing debuggers and related things. They contain a portion of the program state extracted during the handling of an exception (usually the most recent exception).

In the absence of circularities and tracebacks, Python programs need not explicitly manage memory.

Why doesn’t Python use a more traditional garbage collection scheme? For one thing, this is not a C standard feature and hence it’s not portable. (Yes, we know about the Boehm GC library. It has bits of assembler code for most common platforms, not for all of them, and although it is mostly transparent, it isn’t completely transparent; patches are required to get Python to work with it.)

Traditional GC also becomes a problem when Python is embedded into other applications. While in a standalone Python it’s fine to replace the standard malloc() and free() with versions provided by the GC library, an application embedding Python may want to have its own substitute for malloc() and free(), and may not want Python’s. Right now, Python works with anything that implements malloc() and free() properly.

In Jython, the following code (which is fine in CPython) will probably run out of file descriptors long before it runs out of memory:

for file in <very long list of files>:
f = open(file)
c = f.read(1)

Using the current reference counting and destructor scheme, each new assignment to f closes the previous file. Using GC, this is not guaranteed. If you want to write code that will work with any Python implementation, you should explicitly close the file; this will work regardless of GC:

for file in <very long list of files>:
f = open(file)
c = f.read(1)
f.close()


]]>
Python 寰幆寮曠敤瀵艱嚧鍐呭瓨娉勬紡鐨勫唴瀛樼鐞員EST ref from錛歨ttp://meizhini.javaeye.com/blog/249716http://www.tkk7.com/yglwxl/archive/2009/11/30/304229.html涔?jié)瀹?/dc:creator>涔?jié)瀹?/author>Mon, 30 Nov 2009 02:47:00 GMThttp://www.tkk7.com/yglwxl/archive/2009/11/30/304229.htmlhttp://www.tkk7.com/yglwxl/comments/304229.htmlhttp://www.tkk7.com/yglwxl/archive/2009/11/30/304229.html#Feedback0http://www.tkk7.com/yglwxl/comments/commentRss/304229.htmlhttp://www.tkk7.com/yglwxl/services/trackbacks/304229.html     鍥犱負 Python 鏈変簡鑷姩鍨冨溇鍥炴敹鍔熻兘錛屼笉灝戝垵瀛﹁呭氨璁や負鑷繁浠庢榪囦笂浜嗗ソ鏃ュ瓙錛屼笉蹇呭啀鍙楀唴瀛樻硠婕忕殑楠氭壈浜嗐備絾濡傛灉鏌ョ湅涓涓?Python 鏂囨。瀵?__del__() 鍑芥暟鐨勬弿榪幫紝灝辯煡閬撳ソ鏃ュ瓙閲屼篃鏄湁闃翠簯鐨勩備笅闈㈡憳鎶勪竴鐐規(guī)枃妗e唴瀹癸細
    Some common situations that may prevent the reference count of an object from going to zero include: circular references between objects (e.g., a doubly-linked list or a tree data structure with parent and child pointers); a reference to the object on the stack frame of a function that caught an exception (the traceback stored in sys.exc_traceback keeps the stack frame alive); or a reference to the object on the stack frame that raised an unhandled exception in interactive mode (the traceback stored in sys.last_traceback keeps the stack frame alive).
    鍙錛屾湁 __del__() 鍑芥暟鐨勫璞¢棿鐨勫驚鐜紩鐢ㄦ槸瀵艱嚧鍐呭瓨娉勬紡鐨勪富鍑躲傜壒鍒鏄庯細瀵規(guī)病鏈?__del__() 鍑芥暟鐨?Python 瀵硅薄闂寸殑寰幆寮曠敤錛屾槸鍙互琚嚜鍔ㄥ瀮鍦懼洖鏀舵帀鐨勩?br />

鏈?__del__() 鍑芥暟鐨勫璞¢棿鐨勫驚鐜紩鐢ㄦ槸瀵艱嚧鍐呭瓨娉勬紡鐨勪富鍑躲傜壒鍒鏄庯細瀵規(guī)病鏈?__del__() 鍑芥暟鐨?Python 瀵硅薄闂寸殑寰幆寮曠敤錛屾槸鍙互琚嚜鍔ㄥ瀮鍦懼洖鏀舵帀鐨勩傛墍浠ワ紝娌′粈涔堜簨錛屽崈涓囦笉瑕佽交鏄撳惎鐢╛_del__鎿嶄綔銆?br /> 濡備綍鐭ラ亾涓涓璞℃槸鍚﹀唴瀛樻硠婕忎簡鍛紵
    鏂規(guī)硶涓銆佸綋浣犺涓轟竴涓璞″簲璇ヨ閿姣佹椂錛堝嵆寮曠敤璁℃暟涓?0錛夛紝鍙互閫氳繃 sys.getrefcount(obj) 鏉ヨ幏鍙栧璞$殑寮曠敤璁℃暟錛屽茍鏍規(guī)嵁榪斿洖鍊兼槸鍚︿負 0 鏉ュ垽鏂槸鍚﹀唴瀛樻硠婕忋傚鏋滆繑鍥炵殑寮曠敤璁℃暟涓嶄負 0錛岃鏄庡湪姝ゅ埢瀵硅薄 obj 鏄笉鑳借鍨冨溇鍥炴敹鍣ㄥ洖鏀舵帀鐨勩?br />     鏂規(guī)硶浜屻佷篃鍙互閫氳繃 Python 鎵╁睍妯″潡 gc 鏉ユ煡鐪嬩笉鑳藉洖鏀剁殑瀵硅薄鐨勮緇嗕俊鎭?br />

    棣栧厛錛屾潵鐪嬩竴孌墊甯哥殑嫻嬭瘯浠g爜錛?br />
#--------------- code begin --------------

# -*- coding: utf-8 -*-

import gc
import sys

class CGcLeak(object):
    def __init__(self):
        self._text = '#'*10

    def __del__(self):
        pass

def make_circle_ref():
    _gcleak = CGcLeak()
#   _gcleak._self = _gcleak # test_code_1
    print '_gcleak ref count0:%d' % sys.getrefcount(_gcleak)
    del _gcleak
    try:
        print '_gcleak ref count1:%d' % sys.getrefcount(_gcleak)
    except UnboundLocalError:
        print '_gcleak is invalid!'

def test_gcleak():
    # Enable automatic garbage collection.
    gc.enable()
    # Set the garbage collection debugging flags.
    gc.set_debug(gc.DEBUG_COLLECTABLE | gc.DEBUG_UNCOLLECTABLE | \
        gc.DEBUG_INSTANCES | gc.DEBUG_OBJECTS)

    print 'begin leak test...'
    make_circle_ref()

    print 'begin collect...'
    _unreachable = gc.collect()
    print 'unreachable object num:%d' % _unreachable
    print 'garbage object num:%d' % len(gc.garbage)

if __name__ == '__main__':
    test_gcleak()

#--------------- code end ----------------

    鍦?test_gcleak() 涓紝璁劇疆鍨冨溇鍥炴敹鍣ㄨ皟璇曟爣蹇楀悗錛屽啀鐢?collect() 榪涜鍨冨溇鍥炴敹錛屾渶鍚庢墦鍗板嚭璇ユ鍨冨溇鍥炴敹鍙戠幇鐨勪笉鍙揪鐨勫瀮鍦懼璞℃暟鍜屾暣涓В閲婂櫒涓殑鍨冨溇瀵硅薄鏁般?br />
    gc.garbage 鏄竴涓?list 瀵硅薄錛屽垪琛ㄩ」鏄瀮鍦炬敹闆嗗櫒鍙戠幇鐨勪笉鍙揪錛堝嵆鏄瀮鍦懼璞★級銆佷絾鍙堜笉鑳介噴鏀撅紙鍗充笉鑳藉洖鏀訛級鐨勫璞°傛枃妗f弿榪頒負錛欰 list of objects which the collector found to be unreachable but could not be freed (uncollectable objects).
    閫氬父錛実c.garbage 涓殑瀵硅薄鏄紩鐢ㄧ幆涓殑瀵硅薄銆傚洜涓?Python 涓嶇煡閬撴寜鐓т粈涔堟牱鐨勫畨鍏ㄦ搴忔潵璋冪敤鐜腑瀵硅薄鐨?__del__() 鍑芥暟錛屽鑷村璞″緇堝瓨媧誨湪 gc.garbage 涓紝閫犳垚鍐呭瓨娉勬紡銆傚鏋滅煡閬撲竴涓畨鍏ㄧ殑嬈″簭錛岄偅涔堝氨鎵撶牬寮曠敤鐜紝鍐嶆墽琛?del gc.garbage[:] 錛屼互娓呯┖鍨冨溇瀵硅薄鍒楄〃銆?br />
    涓婃浠g爜杈撳嚭涓猴紙#鍚庡瓧絎︿覆涓虹瑪鑰呮墍鍔犳敞閲婏級錛?br /> #-----------------------------------------
begin leak test...
# 鍙橀噺 _gcleak 鐨勫紩鐢ㄨ鏁頒負 2.
_gcleak ref count0:2
# _gcleak 鍙樹負涓嶅彲杈?unreachable)鐨勯潪娉曞彉閲?
_gcleak is invalid!
# 寮濮嬪瀮鍦懼洖鏀?br /> begin collect...
# 鏈鍨冨溇鍥炴敹鍙戠幇鐨勪笉鍙揪鐨勫瀮鍦懼璞℃暟涓?0.
unreachable object num:0
# 鏁翠釜瑙i噴鍣ㄤ腑鐨勫瀮鍦懼璞℃暟涓?0.
garbage object num:0
#-----------------------------------------
    鍙 _gcleak 瀵硅薄鐨勫紩鐢ㄨ鏁版槸姝g‘鐨勶紝涔熸病鏈変換浣曞璞″彂鐢熷唴瀛樻硠婕忋?br />
    濡傛灉涓嶆敞閲婃帀 make_circle_ref() 涓殑 test_code_1 璇彞錛?br />     _gcleak._self = _gcleak
涔熷氨鏄 _gcleak 褰㈡垚涓涓嚜宸卞鑷繁鐨勫驚鐜紩鐢ㄣ傚啀榪愯涓婅堪浠g爜錛岃緭鍑虹粨鏋滃氨鍙樻垚錛?br /> #-----------------------------------------
begin leak test...
_gcleak ref count0:3
_gcleak is invalid!
begin collect...
# 鍙戠幇鍙互鍥炴敹鐨勫瀮鍦懼璞? 鍦板潃涓?012AA090錛岀被鍨嬩負 CGcLeak.
gc: uncollectable <CGcLeak 012AA090>
gc: uncollectable <dict 012AC1E0>
unreachable object num:2
#!! 涓嶈兘鍥炴敹鐨勫瀮鍦懼璞℃暟涓?1錛屽鑷村唴瀛樻硠婕忥紒
garbage object num:1
#-----------------------------------------
    鍙 <CGcLeak 012AA090> 瀵硅薄鍙戠敓浜嗗唴瀛樻硠婕忥紒錛佽屽鍑虹殑 dict 鍨冨溇灝辨槸娉勬紡鐨?_gcleak 瀵硅薄鐨勫瓧鍏革紝鎵撳嵃鍑哄瓧鍏鎬俊鎭負:
{'_self': <__main__.CGcLeak object at 0x012AA090>, '_text': '##########'}

    闄や簡瀵硅嚜宸辯殑寰幆寮曠敤錛屽涓璞¢棿鐨勫驚鐜紩鐢ㄤ篃浼氬鑷村唴瀛樻硠婕忋傜畝鍗曚婦渚嬪涓嬶細

#--------------- code begin --------------

class CGcLeakA(object):
    def __init__(self):
        self._text = '#'*10

    def __del__(self):
        pass

class CGcLeakB(object):
    def __init__(self):
        self._text = '*'*10

    def __del__(self):
        pass

def make_circle_ref():
    _a = CGcLeakA()
    _b = CGcLeakB()
    _a._b = _b  # test_code_2
    _b._a = _a  # test_code_3
    print 'ref count0:a=%d b=%d' % \
        (sys.getrefcount(_a), sys.getrefcount(_b))
#   _b._a = None    # test_code_4
    del _a
    del _b
    try:
        print 'ref count1:a=%d' % sys.getrefcount(_a)
    except UnboundLocalError:
        print '_a is invalid!'
    try:
        print 'ref count2:b=%d' % sys.getrefcount(_b)
    except UnboundLocalError:
        print '_b is invalid!'

#--------------- code end ----------------

    榪欐嫻嬭瘯鍚庤緭鍑虹粨鏋滀負錛?br /> #-----------------------------------------
begin leak test...
ref count0:a=3 b=3
_a is invalid!
_b is invalid!
begin collect...
gc: uncollectable <CGcLeakA 012AA110>
gc: uncollectable <CGcLeakB 012AA0B0>
gc: uncollectable <dict 012AC1E0>
gc: uncollectable <dict 012AC0C0>
unreachable object num:4
garbage object num:2
#-----------------------------------------
鍙 _a,_b 瀵硅薄閮藉彂鐢熶簡鍐呭瓨娉勬紡銆傚洜涓轟簩鑰呮槸寰幆寮曠敤錛屽瀮鍦懼洖鏀跺櫒涓嶇煡閬撹濡備綍鍥炴敹錛屼篃灝辨槸涓嶇煡閬撹棣栧厛璋冪敤閭d釜瀵硅薄鐨?__del__() 鍑芥暟銆?br />
    閲囩敤浠ヤ笅浠諱竴鏂規(guī)硶錛屾墦鐮寸幆鐘跺紩鐢紝灝卞彲浠ラ伩鍏嶅唴瀛樻硠婕忥細
[1] 娉ㄩ噴鎺?make_circle_ref() 涓殑 test_code_2 璇彞錛?br /> [2] 娉ㄩ噴鎺?make_circle_ref() 涓殑 test_code_3 璇彞錛?br /> [3] 鍙栨秷瀵?make_circle_ref() 涓殑 test_code_4 璇彞鐨勬敞閲娿?br /> 鐩稿簲杈撳嚭緇撴灉鍙樹負錛?br /> #-----------------------------------------
begin leak test...
ref count0:a=2 b=3  # 娉細姝ゅ杈撳嚭緇撴灉瑙嗘儏鍐靛彉鍖?
_a is invalid!
_b is invalid!
begin collect...
unreachable object num:0
garbage object num:0
#-----------------------------------------


    緇撹錛歅ython 鐨?gc 鏈夋瘮杈冨己鐨勫姛鑳斤紝姣斿璁劇疆 gc.set_debug(gc.DEBUG_LEAK) 灝卞彲浠ヨ繘琛屽驚鐜紩鐢ㄥ鑷寸殑鍐呭瓨娉勯湶鐨勬鏌ャ傚鏋滃湪寮鍙戞椂榪涜鍐呭瓨娉勯湶媯鏌ワ紱鍦ㄥ彂甯冩椂鑳藉紜繚涓嶄細鍐呭瓨娉勯湶錛岄偅涔堝氨鍙互寤墮暱 Python 鐨勫瀮鍦懼洖鏀舵椂闂撮棿闅斻佺敋鑷充富鍔ㄥ叧闂瀮鍦懼洖鏀舵満鍒訛紝浠庤屾彁楂樿繍琛屾晥鐜囥?br />

]]>
Come from : Python婧愮爜鍓栨瀽鈥斺擯ython鐨勫唴瀛樼鐞嗘満鍒?/title><link>http://www.tkk7.com/yglwxl/archive/2009/11/30/304225.html</link><dc:creator>涔?jié)瀹?/dc:creator><author>涔?jié)瀹?/author><pubDate>Mon, 30 Nov 2009 02:35:00 GMT</pubDate><guid>http://www.tkk7.com/yglwxl/archive/2009/11/30/304225.html</guid><wfw:comment>http://www.tkk7.com/yglwxl/comments/304225.html</wfw:comment><comments>http://www.tkk7.com/yglwxl/archive/2009/11/30/304225.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/yglwxl/comments/commentRss/304225.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/yglwxl/services/trackbacks/304225.html</trackback:ping><description><![CDATA[1.灝忓潡絀洪棿鐨勫唴瀛樻睜<br /> 鍦≒ython涓紝璁稿鏃跺欑敵璇風殑鍐呭瓨閮芥槸灝忓潡鐨勫唴瀛橈紝榪欎簺灝忓潡鍐呭瓨鍦ㄧ敵璇峰悗錛屽緢蹇張浼?br /> 琚噴鏀撅紝鐢變簬榪欎簺鍐呭瓨鐨勭敵璇峰茍涓嶆槸涓轟簡鍒涘緩瀵硅薄錛屾墍浠ュ茍娌℃湁瀵硅薄涓綰х殑鍐呭瓨姹犳満鍒躲傝繖灝?br /> 鎰忓懗鐫Python鍦ㄨ繍琛屾湡闂翠細澶ч噺鍦版墽琛宮alloc鍜宖ree鐨勬搷浣滐紝棰戠箒鍦板湪鐢ㄦ埛鎬佸拰鏍稿績鎬佷箣闂?br /> 榪涜鍒囨崲錛岃繖灝嗕弗閲嶅獎鍝峆ython鐨勬墽琛屾晥鐜囥備負浜嗗姞閫烶ython鐨勬墽琛屾晥鐜囷紝Python寮曞叆浜嗕竴<br /> 涓唴瀛樻睜鏈哄埗錛岀敤浜庣鐞嗗灝忓潡鍐呭瓨鐨勭敵璇峰拰閲婃斁銆傝繖涔熷氨鏄箣鍓嶆彁鍒扮殑Pymalloc鏈哄埗.<br /> <br /> 2.鍦≒ython2.5涓紝Python鍐呴儴榛樿鐨勫皬鍧楀唴瀛樹笌澶у潡鍐呭瓨鐨勫垎鐣岀偣瀹氬湪256涓瓧鑺傦紝榪欎釜<br /> 鍒嗙晫鐐圭敱鍓嶉潰鎴戜滑鐪嬪埌鐨勫悕涓篠MALL_REQUEST_THRESHOLD鐨勭鍙鋒帶鍒躲備篃灝辨槸璇達紝褰撶敵<br /> 璇風殑鍐呭瓨灝忎簬256瀛楄妭鏃訛紝PyObject_Malloc浼氬湪鍐呭瓨姹犱腑鐢寵鍐呭瓨錛涘綋鐢寵鐨勫唴瀛樺ぇ浜?56<br /> 瀛楄妭鏃訛紝PyObject_Malloc鐨勮涓哄皢铚曞寲涓簃alloc鐨勮涓恒傚綋鐒訛紝閫氳繃淇敼Python婧愪唬鐮侊紝鎴?br /> 浠彲浠ユ敼鍙樿繖涓粯璁ゅ鹼紝浠庤屾敼鍙楶ython鐨勯粯璁ゅ唴瀛樼鐞嗚涓恒?<br /> <br /> 3.鍦ㄤ竴涓璞$殑寮曠敤璁℃暟鍑忎負0鏃訛紝涓庤瀵硅薄瀵瑰簲鐨勬瀽鏋勫嚱鏁板氨浼氳璋冪敤錛屼絾鏄鐗瑰埆娉ㄦ剰鐨勬槸錛岃皟鐢ㄦ瀽鏋勫嚱鏁板茍涓嶆剰鍛崇潃鏈緇堜竴瀹氫細璋冪敤free閲婃斁鍐呭瓨絀洪棿錛屽鏋滅湡鏄繖鏍風殑璇濓紝閭i綣佸湴鐢寵銆侀噴鏀懼唴瀛樼┖闂翠細浣?<span id="dlv9pp9" class="hilite1">Python</span>鐨勬墽琛屾晥鐜囧ぇ鎵撴姌鎵o紙鏇翠綍鍐?span class="hilite1">Python</span>宸茬粡澶氬勾鑳岃礋浜嗕漢浠鍏舵墽琛屾晥鐜囩殑涓嶆弧錛夈備竴鑸潵璇達紝<span id="7dxhb9f" class="hilite1">Python</span>涓ぇ閲忛噰鐢ㄤ簡鍐呭瓨瀵硅薄姹犵殑鎶鏈紝浣跨敤榪欑鎶鏈彲浠ラ伩鍏嶉綣佸湴鐢寵鍜岄噴鏀懼唴瀛樼┖闂淬傚洜姝ゅ湪鏋愭瀯鏃訛紝閫氬父閮芥槸灝嗗璞″崰鐢ㄧ殑絀洪棿褰掕繕鍒板唴瀛樻睜涓?br /> "榪欎釜闂灝辨槸:<span id="79zrdlj" class="hilite1">Python</span>鐨刟rena浠庢潵涓嶉噴鏀緋ool銆傝繖涓棶棰樹負浠涔堜細寮曡搗綾諱技浜庡唴瀛樻硠婕忕殑鐜拌薄鍛€傝冭檻榪欐牱涓縐嶆儏褰紝鐢寵10*1024*1024涓?6瀛楄妭鐨勫皬鍐呭瓨錛岃繖灝辨剰鍛崇潃蹇呴』浣跨敤160M鐨勫唴瀛橈紝鐢變簬<span id="fvx799z" class="hilite1">Python</span>娌℃湁榛樿灝嗗墠闈㈡彁鍒扮殑闄愬埗鍐呭瓨姹犵殑WITH_MEMORY_LIMITS緙栬瘧絎﹀彿鎵撳紑錛屾墍浠?span class="hilite1">Python</span>浼氬畬鍏ㄤ嬌鐢╝rena鏉ユ弧瓚充綘鐨勯渶姹傦紝榪欓兘娌℃湁闂錛屽叧閿殑闂鍦ㄤ簬榪囦簡涓孌墊椂闂達紝浣犲皢鎵鏈夎繖浜?6瀛楄妭鐨勫唴瀛橀兘閲婃斁浜嗭紝榪欎簺鍐呭瓨閮藉洖鍒癮rena鐨勬帶鍒朵腑錛屼技涔庢病鏈夐棶棰樸備絾鏄棶棰樻伆鎭板氨鍦ㄨ繖鏃跺嚭鐜頒簡銆傚洜涓篴rena濮嬬粓涓嶄細閲婃斁瀹冪淮鎶ょ殑pool闆嗗悎錛屾墍浠ヨ繖160M鐨勫唴瀛樺緇堣<span id="dtvrjj7" class="hilite1">Python</span>鍗犵敤錛屽鏋滀互鍚庣▼搴忚繍琛屼腑鍐嶄篃涓嶉渶瑕?60M濡傛宸ㄥぇ鐨勫唴瀛橈紝 <br /> 榪欑偣鍐呭瓨宀備笉鏄氨嫻垂浜嗭紵" <br /> <span id="x71n999" class="hilite1">python</span>鍐呭瓨綆$悊瑙勫垯:<br /> del鐨勬椂鍊?鎶妉ist鐨勫厓绱犻噴鏀炬帀,鎶婄鐞嗗厓绱犵殑澶у璞″洖鏀跺埌py瀵硅薄緙撳啿姹犻噷. <br /> <img src ="http://www.tkk7.com/yglwxl/aggbug/304225.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/yglwxl/" target="_blank">涔?jié)瀹?/a> 2009-11-30 10:35 <a href="http://www.tkk7.com/yglwxl/archive/2009/11/30/304225.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>Python 灝忓潡絀洪棿鍐呭瓨綆$悊TEST ref from錛?http://www.javaeye.com/topic/309753http://www.tkk7.com/yglwxl/archive/2009/11/27/303916.html涔?jié)瀹?/dc:creator>涔?jié)瀹?/author>Fri, 27 Nov 2009 08:54:00 GMThttp://www.tkk7.com/yglwxl/archive/2009/11/27/303916.htmlhttp://www.tkk7.com/yglwxl/comments/303916.htmlhttp://www.tkk7.com/yglwxl/archive/2009/11/27/303916.html#Feedback1http://www.tkk7.com/yglwxl/comments/commentRss/303916.htmlhttp://www.tkk7.com/yglwxl/services/trackbacks/303916.htmldef test():
   for i in range ( 1000000 * 10 ):
        del i

if ( __name__ == "__main__" ):
    test()
    while ( True ):
        time.sleep( 1 )
瑙傚療mem:鍐呭瓨緇存寔涓嶅彉! 

浠庤繖鐐瑰彲浠ョ寽嫻?python涓嶆槸绔嬪嵆閲婃斁璧勬簮鐨?

涓漢嫻嬭瘯浠g爜:
-----------------------------------------------test0.py-------------------------------------

import time

def test():
    for i in range ( 1000000 * 10 ):
        del i


def test_2():
    #i = range ( 1000000 * 10 )
    #del i
    pass

def test_3():
    #i = "*" * ( 1000000 * 10 )
    #del i
    pass


if ( __name__ == "__main__" ):
    for i in range( 10 ):
        test()
        test_2()
        test_3()
        time.sleep( 1 )
    while ( True ):
        time.sleep( 1 )
-----------------------------------------------------test0.py-------------------------------------- 

榪愯 python test0.py

"while ( True ):
        time.sleep( 1 )
 "
淇濊瘉python涓嶉鍑?

鍙戠幇python鐨勫唴瀛樺崰鐢ㄧ巼涓?0%.

 

濡備綍瑙e喅榪欎釜闂鍛?鐪嬩笅闈㈢殑:

-----------------------------------------------test1.py-------------------------------------

#coding=utf-8
import time

max_number = 1000000 * 10
def test_0():
    for i in range ( max_number ):
        del i

def test_1():
    for i in range( 1000 ):
        for i in range ( max_number / 1000 ):
            del i

if ( __name__ == "__main__" ):
    #test_0()#鍐呭瓨浣跨敤鐜囧崰40%
    test_1()#鍐呭瓨浣跨敤鐜囧崰0.2%
 
    print "---------------------"
    while ( True ):
        time.sleep( 1 )

-----------------------------------------------test1.py-------------------------------------

 鎴戞兂闂:闂涔熻瑙e喅浜?

榪欏氨瑕佺湅浣犵殑瀹為檯闇姹傛槸浠涔堜簡.

渚嬪:

鎴戝仛榪囦竴涓埇铏▼搴?濡傛灉涓嶆柇寰榪欎釜綰跨▼閲岄潰浼犻抲rl,閭d箞榪欎釜綰跨▼涓嶅埌涓浼氬氨鎸備簡.鎴戠殑鏀硅繘鏂規(guī)硶:灝辨槸鎺у埗榪欑嚎紼嬭兘澶熸帴鍙楃殑url闃熷垪闀垮害.浠ュ強鍏朵粬鐨勪紭鍖?
 鍏跺疄榪欎釜涓嶆槸寰幆瀵艱嚧鐨勫唴瀛樿python鎸佹湁,鑰屾槸range( n )璁﹑ython鍒嗛厤浜嗗緢澶氱殑鍐呭瓨.閫鍑簍est(),python鍥炴敹鍐呭瓨,浣嗘槸python騫朵笉閲婃斁浜?鑰屾槸璁﹑ool鎸佹湁鍐呭瓨絀洪棿.



]]>
Python- 鏄犲皠 listhttp://www.tkk7.com/yglwxl/archive/2009/05/14/270575.html涔?jié)瀹?/dc:creator>涔?jié)瀹?/author>Thu, 14 May 2009 03:57:00 GMThttp://www.tkk7.com/yglwxl/archive/2009/05/14/270575.htmlhttp://www.tkk7.com/yglwxl/comments/270575.htmlhttp://www.tkk7.com/yglwxl/archive/2009/05/14/270575.html#Feedback0http://www.tkk7.com/yglwxl/comments/commentRss/270575.htmlhttp://www.tkk7.com/yglwxl/services/trackbacks/270575.html >>>params.keys()
['a', 's', 'b']
>>>params.values()
['av', 'sv', 'bv']
>>>params.items()
[('a', 'av'), ('s', 'sv'), ('b', 'bv')]
>>>[k for k,v in params.items()]
['a', 's', 'b']
>>>[v for k,v in params.items()]
['av', 'sv', 'bv']
>>>["%s=%s" % (k,v) for k,v in params.items()]
['a=av', 's=sv', 'b=bv']

]]>
Python study- List extend() and append()http://www.tkk7.com/yglwxl/archive/2009/05/14/270562.html涔?jié)瀹?/dc:creator>涔?jié)瀹?/author>Thu, 14 May 2009 03:15:00 GMThttp://www.tkk7.com/yglwxl/archive/2009/05/14/270562.htmlhttp://www.tkk7.com/yglwxl/comments/270562.htmlhttp://www.tkk7.com/yglwxl/archive/2009/05/14/270562.html#Feedback0http://www.tkk7.com/yglwxl/comments/commentRss/270562.htmlhttp://www.tkk7.com/yglwxl/services/trackbacks/270562.html >>>li=['a','b']
>>>li.extend(['c','d'])
>>>li
['a', 'b', 'c', 'd']
>>>li.append(['e','f'])
>>>li
['a', 'b', 'c', 'd',['e','f']]

2. 鎼滅儲 鎼滅儲 list
>>>li.index('b')
>>>li
1

3. List 榪愮畻絎︼紜 鍜?×
>>> li = ['a', 'b']
>>> li = li + ['example', 'new'] 
>>> li
['a', 'b', 'example', 'new']
>>> li += ['two']              
>>> li
['a', 'b', 'example', 'new', 'two']
>>> li = [1, 2] * 3      
>>> li
[1, 2, 1, 2, 1, 2]


4.浣曡皳 Python 涓殑 True
·0涓篺alse;   鍏跺畠鎵鏈夋暟鍊肩殕涓?true銆?br /> ·絀轟覆 ("") 涓篺alse;  鍏跺畠鎵鏈夊瓧絎︿覆鐨嗕負 true銆?br /> ·絀簂ist ([])涓篺alse;  鍏跺畠鎵鏈夊瓧絎︿覆鐨嗕負 true銆?br /> ·絀?tuple (()) 涓篺alse;  鍏跺畠鎵鏈夊瓧絎︿覆鐨嗕負 true銆?br /> ·絀?dictionary ({}) 涓篺alse;  鍏跺畠鎵鏈夊瓧絎︿覆鐨嗕負 true銆?

]]>
主站蜘蛛池模板: 亚洲一区二区三区91| 亚洲福利在线观看| 亚洲人成网站免费播放| 国产精品成人免费福利| 精品亚洲AV无码一区二区三区 | 国产亚洲综合一区二区三区| 成人无遮挡毛片免费看| 亚洲日韩一中文字暮| 日韩免费观看的一级毛片| 久久亚洲精品高潮综合色a片| 免费无码黄动漫在线观看| 婷婷国产偷v国产偷v亚洲| 国产又大又粗又硬又长免费 | 亚洲AV中文无码乱人伦| 成人a毛片免费视频观看| 亚洲春色在线视频| 最好看最新的中文字幕免费| 亚洲a级片在线观看| 国产免费人视频在线观看免费| 青娱乐在线视频免费观看| 国产成人亚洲精品影院| 无码国产精品一区二区免费16| 亚洲明星合成图综合区在线| 在线中文高清资源免费观看| 疯狂做受xxxx高潮视频免费| 久久91亚洲人成电影网站| 永久黄色免费网站| 青青青亚洲精品国产| 国产美女亚洲精品久久久综合| 久久免费的精品国产V∧| 亚洲精品无码久久| 亚洲乱码精品久久久久..| 4hu四虎最新免费地址| 青青青视频免费观看| 亚洲一区中文字幕久久| 国产精品嫩草影院免费| 国产免费一区二区视频| 亚洲最大中文字幕无码网站 | 亚洲人成色99999在线观看| 亚洲日本va午夜中文字幕久久 | 免费观看理论片毛片|