线程_可能发生的问题

2021-01-27 10:15

阅读:692

标签:init   产生   sof   str   对象产生   +=   time   color   star   

from threading import Thread
g_num = 0
def test1():
    global g_num
    for i in range(1000000):
        g_num += 1
    print("---test1---g_num=%d"%g_num)
def test2():
    global g_num
    for i in range(1000000):
        g_num += 1
    print("---test2---g_num=%d"%g_num)
p1 = Thread(target=test1)
p1.start()
# time.sleep(3)

p2 = Thread(target=test2)
p2.start()

print("---g_num=%d---"%g_num)

内存泄漏
import gc
class ClassA():
    def __init__(self):
        print(对象产生 id:%s%str(hex(id(self))))
def f2():
    while True:
        c1 = ClassA()
        c2 = ClassA()
        c1.t = c2#引用计数变为2
        c2.t = c1
        del c1#引用计数变为1  0才进行回收
        del c2
#把python的gc关闭
gc.disable()
f2()

2020-05-07

线程_可能发生的问题

标签:init   产生   sof   str   对象产生   +=   time   color   star   

原文地址:https://www.cnblogs.com/hany-postq473111315/p/12845683.html


评论


亲,登录后才可以留言!