I'm writing an OPC client so I use the Python OpenOPC library.
The problem is each time I'm reading a list of OPC items, my app consume memory.
For example, the following code consume about 100ko at each iteration :
#!/usr/bin/python
# -*- coding: utf-8 -*-
import OpenOPC
import time
import gc
gc.set_debug(gc.DEBUG_LEAK)
client = OpenOPC.client()
while True:
client.connect('CODESYS.OPC.DA')
dataList = client.list("PLC2.Application.GVL.*")
res = client.read(dataList)
client.close()
print gc.collect()
print gc.garbage
time.sleep(2)
and the garbage collector returns :
0
[]
The memory is released when I close the app.
So I don't understand why my app leaks memory and how avoid this.
Have you some ideas ? Thanks
Found a solution by using the group argument of the read() function :
#!/usr/bin/python
# -*- coding: utf-8 -*-
import OpenOPC
client = OpenOPC.client()
client.connect('CODESYS.OPC.DA')
tags = client.list("PLC2.Application.GVL.*")
while True:
res = client.read(tags, group='MyGroup')
client.close()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With