Hello,
Context :
Version: 2023.2 (build 15677)
Build Hash: 5074156dc
Compile Date: 2023-11-25 16:50:41
dzVents Version: 3.1.8
Python Version: 3.9.2 (default, Mar 12 2021, 04:06:34) [GCC 10.2.1 20210110]
Boost-1.83.0
Issue :
I have implemented several python plugin and from a function point of view they are working fine since many years.
However since my upgrade to Domoticz 2023.2 and the OS upgrade to bullseye and python 3.9.2 I have the following messages when stopping a python plugin for each device declared within the plugin.
Error: "HARDWARE_NAME": Stop: Device 'DEVICE_NAME' Reference Count not correct, expected 1 found 2
For example I have a Water Meter python plugin (HARDWARE_NAME=Eau Ville) with 3 devices. When stopping it I get in domoticz.log:
2023-11-27 09:01:45.296 Error: EauVille: Stop: Device 'EauVille - Current usage' Reference Count not correct, expected 1 found 2.
2023-11-27 09:01:45.296 Error: EauVille: Stop: Device 'EauVille - Total usage' Reference Count not correct, expected 1 found 2.
2023-11-27 09:01:45.296 Error: EauVille: Stop: Device 'EauVille - Wifi signal' Reference Count not correct, expected 1 found 2.
Findings:
I did some investigation and added some extra code lines in Plugins.cpp CPlugin::Start method line 1470 to check the pDevice refcount at the end of the Start method
PyBorrowedRef Testkey;
PyBorrowedRef TestpDevice;
Py_ssize_t Testpos = 0;
while (PyDict_Next((PyObject*)m_DeviceDict, &Testpos, &Testkey, &TestpDevice))
{
PyNewRef TestpName = PyObject_GetAttrString(TestpDevice, "Name");
Log(LOG_STATUS, "### VERIFICATION DeviceID %s Reference Count found %d.", std::string(TestpName).c_str() , (int)TestpDevice->ob_refcnt);
}
As result of this I get in Domoticz.log at the end of the Start method:
2023-11-27 09:20:32.660 Status: EauVille: ### VERIFICATION DeviceID EauVille - Current usage Reference Count found 2.
2023-11-27 09:20:32.660 Status: EauVille: ### VERIFICATION DeviceID EauVille - Total usage Reference Count found 2.
2023-11-27 09:20:32.660 Status: EauVille: ### VERIFICATION DeviceID EauVille - Wifi signal Reference Count found 2.
To give some more details the lines incrementing the Reference Count are:
line 1441 : PyNewRef pDevice = PyObject_CallObject((PyObject *)pModState->pDeviceClass, nrArgList); ---> pDevice refcount 1
line 1452 : if (PyDict_SetItem((PyObject*)m_DeviceDict, pKey, pDevice) == -1) ---> pDevice refcount 2
line 1460 : PyNewRef pRefresh = PyObject_GetAttrString(pDevice, "Refresh"); ---> pDevice refcount 3
When PyNewRef pDevice is assigned again (next item in the loop) or goes out of scope refcount is decremented. ---> pDevice refcount 2
The weird thing is that PyObject_GetAttrString is called twice and behaves differently with respect to the pDevice refcount :
Line 1449 : PyNewRef pKey = PyObject_GetAttrString(pDevice, "Key"); ---> with no impact on pDevice Refcount
line 1460 : PyNewRef pRefresh = PyObject_GetAttrString(pDevice, "Refresh"); ---> with the incrementation of pDevice refcount
My questions are:
- is anybody facing this issue in his domoticz implementation ?
- Should not we decrement the reference count after the execution of line 1460 ?
BR
Stop: Device 'XXX' Reference Count not correct, expected 1
Moderator: leecollings
Who is online
Users browsing this forum: No registered users and 1 guest