Hello, I have a problem with the IPv6 UDP connection in Python. I discovered that there is a resource leak if the library was unable to establish a connection.
I poll my counters in a loop, if the connection to the counter fails I get an error
"Failed to receive reply from the device in given time". My code moves on to the next iteration and I see that a new thread is being spawned, and so on every time.
active_threads = threading.enumerate()
for thread in active_threads:
print("Thread ID:", thread.ident)
print("Thread Name:", thread.name)
Thread Name: Thread-4 (__listenerThread)
Thread ID: 2958029856
Thread Name: Thread-6 (__listenerThread)
Thread ID: 2949637152
Thread Name: Thread-8 (__listenerThread)
Thread ID: 2941244448
Thread Name: Thread-10 (__listenerThread)
Thread ID: 2932589600
Thread Name: Thread-12 (__listenerThread)
Thread ID: 2923410464
Thread Name: Thread-14 (__listenerThread)
Thread ID: 2914755616
Thread Name: Thread-16 (__listenerThread)
Thread ID: 2906100768
Thread Name: Thread-18 (__listenerThread)
Thread ID: 2897183776
Thread Name: Thread-20 (__listenerThread)
Thread ID: 2888791072
Thread Name: Thread-22 (__listenerThread)
Thread ID: 2880398368
Thread Name: Thread-24 (__listenerThread)
Thread ID: 2872005664
Thread Name: Thread-26 (__listenerThread)
Thread ID: 2863612960
Thread Name: Thread-28 (__listenerThread)
Thread ID: 2855220256
Thread Name: Thread-30 (__listenerThread)
Thread ID: 2846827552
Thread Name: Thread-32 (__listenerThread)
Thread ID: 2838434848
Thread Name: Thread-34 (__listenerThread)
Thread ID: 2830042144
Thread Name: Thread-36 (__listenerThread)
I solved my problem, you can…
I solved my problem, you can add self.media.close() before the error in readDLMSPacket2 method. If it is an IP connection.
Hi, Don't add media close to…
Hi,
Don't add media close to the readDLMSPacket2. It's common that the meter might return an error, e.g. if you try to write a value that is read-only. Now the connection hangs and some meters don't respond until inactivity timeout has passed.
The correct way to close the media is after you have closed the connection and call disconnectRequest.
BR,
Mikko