LarsMichelsen/pmatic

Maximum recursion depth exceeded while calling a Python object

Jaydyou opened this issue · 5 comments

After some minutes of running the temperature update example on an Raspberrypi in conjunction with an CCU2 I get the following exception, which seems then repeated for all further updates:

2016-06-30 09:23:20,719 [ERROR] Exception in XML-RPC call event('pmatic-0', 'MEQ0799086:4', 'CONTROL_MODE', 0):
Traceback (most recent call last):
  File "build/bdist.linux-armv7l/egg/pmatic/events.py", line 349, in _dispatch
    return func(*params)
  File "build/bdist.linux-armv7l/egg/pmatic/events.py", line 378, in event
    param = obj.values[value_key]
  File "build/bdist.linux-armv7l/egg/pmatic/entities.py", line 219, in values
    self._fetch_values()
  File "build/bdist.linux-armv7l/egg/pmatic/entities.py", line 305, in _fetch_values
    self._values[param_id].set_from_api(value)
  File "build/bdist.linux-armv7l/egg/pmatic/params.py", line 184, in set_from_api
    return self._set_value(self._from_api_value(value))
  File "build/bdist.linux-armv7l/egg/pmatic/params.py", line 416, in _set_value
    return super(ParameterFLOAT, self)._set_value(float(value))
  File "build/bdist.linux-armv7l/egg/pmatic/params.py", line 203, in _set_value
    self._callback("value_updated")
  File "build/bdist.linux-armv7l/egg/pmatic/utils.py", line 111, in _callback
    raise PMException("Exception in callback (%s - %s): %s" % (cb_name, callback, e))
PMException: Exception in callback (value_updated - <function print_summary_state at 0x76ac9bf0>): Exception in callback (value_updated - <function print_summary_state at 0x76ac9bf0>): Exception in callback (value_updated - <function print_summary_state at 0x76ac9bf0>): Exception in callback (value_updated - <function print_summary_state at 0x76ac9bf0>): Exception in callback (value_updated - <function print_summary_state at 0x76ac9bf0>): Exception in callback (value_updated - <function print_summary_state at 0x76ac9bf0>): Exception in callback (value_updated - <function print_summary_state at 0x76ac9bf0>): Exception in callback (value_updated - <function print_summary_state at 0x76ac9bf0>): Exception in callback (value_updated - <function print_summary_state at 0x76ac9bf0>): Exception in callback (value_updated - <function 
[ much more lines like this ]
Exception in callback (value_updated - <function print_summary_state at 0x76ac9bf0>):
[/]
 Unable to open "http://10.90.90.80/api/homematic.cgi" [RuntimeError]: maximum recursion depth exceeded while calling a Python object

Which pmatic version did you use?

First I tried the version which pip installs, but the problem persists with the latest git version (7ad6c42) of pmatic on Python 2.7.9.

param.channel.summary_state seems to trigger an update check of the values of the corresponding Channel. After the 60 seconds timeout an update is performed and the update-callback-function is triggered while it has not finished yet. Thats causing the endless loop.

The root cause is how the function _value_update_needed works.

  1. Check if at least one parameter within the channel needs an update. If this is true continue with step 2
  2. First parameter is updated, triggering the callback again
  3. Now the first parameter does not require an update, but all other parameters are too old.
  4. First parameter is updated (despite it was updated recently), triggering the callback again
  5. Goto 2

The recursion issue of the callbacks should be fixed in current git build.

Thanks for the fix, now it is working as expected.