使用pywin32com进行opc的内存泄漏

时间:2014-07-02 15:42:39

标签: python com pywin32 opc

我很难弄清楚如何解决泄漏的记忆问题。我认为这可能是pywin32的问题,但我不完全确定。

我的读/写单个项目的代码似乎工作得很好,但是当使用组函数时,它会慢慢泄漏内存。我怀疑这是来自基于1的数组,必须在server_handles中传递。

有没有人知道一项工作?

def read_group(self, group, mode=OPC_SYNC, source=OPC_DS_CACHE):
    """ Read a group returning a list of Result tuples or None. """
    if group not in self.groups:
        raise OPCError("Group does not exist, add first.")

    items = []
    server_handles = []
    for name, item in self.items.items():
        if item.group == group:
            items.append(name)
            server_handles.append(item.server_handle)

    if not server_handles:
        return None

    # Note that arrays are 1 based so must add an element to beginning
    server_handles.insert(0, 0)

    if mode == OPC_SYNC:
        val, err, qual, ts = self.groups[group].SyncRead(
                Source=source,
                NumItems=len(server_handles) - 1,
                ServerHandles=server_handles)

        # Map the return arrays into a list of result tuples
        result = []
        for i in range(len(items)):
            result.append(Result(
                    items[i],
                    val[i],
                    OPC_QUALITY[qual[i]],
                    str(ts[i]),
                    err[i],
                    ))

        return result

0 个答案:

没有答案