相关疑难解决方法(0)

Python 在线程内调用时排队内存泄漏

我有 python TCP 客户端,需要循环发送媒体(.mpg)文件到“C”TCP 服务器。

我有以下代码,在单独的线程中,我正在读取 10K 文件块并发送它,然后在循环中再次执行此操作,我认为这是因为我实现了线程模块或 tcp 发送。我正在使用队列在 GUI ( Tkinter ) 上打印日志,但一段时间后它会耗尽内存。

更新 1 - 根据要求添加更多代码

线程类“Sendmpgthread”用于创建发送数据的线程

.
. 
def __init__ ( self, otherparams,MainGUI):
    .
    .
    self.MainGUI = MainGUI
    self.lock = threading.Lock()
    Thread.__init__(self)

#This is the one causing leak, this is called inside loop
def pushlog(self,msg):
    self.MainGUI.queuelog.put(msg)

def send(self, mysocket, block):
    size = len(block)
    pos = 0;
    while size > 0:
        try:
            curpos = mysocket.send(block[pos:])
        except socket.timeout, msg:
            if self.over:
                 self.pushlog(Exit Send)
                return …
Run Code Online (Sandbox Code Playgroud)

python queue multithreading memory-leaks python-2.7

3
推荐指数
1
解决办法
6515
查看次数

标签 统计

memory-leaks ×1

multithreading ×1

python ×1

python-2.7 ×1

queue ×1