Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

listen_xxx functions dont allow objetcs as custom kwargs #2096

Open
mmattel opened this issue Sep 25, 2024 · 0 comments
Open

listen_xxx functions dont allow objetcs as custom kwargs #2096

mmattel opened this issue Sep 25, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@mmattel
Copy link

mmattel commented Sep 25, 2024

What happened?

I have a setup where an app includes another module. To make the app slim, all major functions are located in that included module. Therefore I handover self as function call parameter and is used as iself in the modules code. This works flawless like for logging. But it breaks when using listeners with custom arguments (kwargs) at the end, see the examples:

Docs does not state any limitations with respect to the type of the value of the named argument, therefore this is either a bug or the docs need to be more precise about the value types allowed.

Version

4.4.2

Installation type

Docker container

Relevant log output

When using an object as kwarg value, this error raises:

Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/appdaemon/events.py", line 249, in process_event mydata = deepcopy(data) File "/usr/local/lib/python3.10/copy.py", line 146, in deepcopy y = copier(x, memo) File "/usr/local/lib/python3.10/copy.py", line 231, in _deepcopy_dict y[deepcopy(key, memo)] = deepcopy(value, memo) File "/usr/local/lib/python3.10/copy.py", line 146, in deepcopy y = copier(x, memo) File "/usr/local/lib/python3.10/copy.py", line 231, in _deepcopy_dict y[deepcopy(key, memo)] = deepcopy(value, memo) File "/usr/local/lib/python3.10/copy.py", line 146, in deepcopy y = copier(x, memo) File "/usr/local/lib/python3.10/copy.py", line 231, in _deepcopy_dict y[deepcopy(key, memo)] = deepcopy(value, memo) File "/usr/local/lib/python3.10/copy.py", line 146, in deepcopy y = copier(x, memo) File "/usr/local/lib/python3.10/copy.py", line 231, in _deepcopy_dict y[deepcopy(key, memo)] = deepcopy(value, memo) File "/usr/local/lib/python3.10/copy.py", line 146, in deepcopy y = copier(x, memo) File "/usr/local/lib/python3.10/copy.py", line 231, in _deepcopy_dict y[deepcopy(key, memo)] = deepcopy(value, memo) File "/usr/local/lib/python3.10/copy.py", line 172, in deepcopy y = _reconstruct(x, memo, *rv) File "/usr/local/lib/python3.10/copy.py", line 271, in _reconstruct state = deepcopy(state, memo) File "/usr/local/lib/python3.10/copy.py", line 146, in deepcopy y = copier(x, memo) File "/usr/local/lib/python3.10/copy.py", line 231, in _deepcopy_dict y[deepcopy(key, memo)] = deepcopy(value, memo) File "/usr/local/lib/python3.10/copy.py", line 172, in deepcopy y = _reconstruct(x, memo, *rv) File "/usr/local/lib/python3.10/copy.py", line 271, in _reconstruct state = deepcopy(state, memo) File "/usr/local/lib/python3.10/copy.py", line 146, in deepcopy y = copier(x, memo) File "/usr/local/lib/python3.10/copy.py", line 231, in _deepcopy_dict y[deepcopy(key, memo)] = deepcopy(value, memo) File "/usr/local/lib/python3.10/copy.py", line 172, in deepcopy y = _reconstruct(x, memo, *rv) File "/usr/local/lib/python3.10/copy.py", line 271, in _reconstruct state = deepcopy(state, memo) File "/usr/local/lib/python3.10/copy.py", line 146, in deepcopy y = copier(x, memo) File "/usr/local/lib/python3.10/copy.py", line 231, in _deepcopy_dict y[deepcopy(key, memo)] = deepcopy(value, memo) File "/usr/local/lib/python3.10/copy.py", line 146, in deepcopy y = copier(x, memo) File "/usr/local/lib/python3.10/copy.py", line 231, in _deepcopy_dict y[deepcopy(key, memo)] = deepcopy(value, memo) File "/usr/local/lib/python3.10/copy.py", line 146, in deepcopy y = copier(x, memo) File "/usr/local/lib/python3.10/copy.py", line 231, in _deepcopy_dict y[deepcopy(key, memo)] = deepcopy(value, memo) File "/usr/local/lib/python3.10/copy.py", line 172, in deepcopy y = _reconstruct(x, memo, *rv) File "/usr/local/lib/python3.10/copy.py", line 271, in _reconstruct state = deepcopy(state, memo) File "/usr/local/lib/python3.10/copy.py", line 146, in deepcopy y = copier(x, memo) File "/usr/local/lib/python3.10/copy.py", line 231, in _deepcopy_dict y[deepcopy(key, memo)] = deepcopy(value, memo) File "/usr/local/lib/python3.10/copy.py", line 161, in deepcopy rv = reductor(4) TypeError: cannot pickle '_thread.RLock' object

Relevant code in the app or config file that caused the issue

Works

	...
	iself.listen_state(entity_cb, entityID)

def entity_cb(entity, attribute, old, new, kwargs):

Works

	...
	iself.listen_state(entity_cb, entityID, arg1="custom")

def entity_cb(entity, attribute, old, new, kwargs):

Fails

	...
	iself.listen_state(entity_cb, entityID, arg1=iself)

def entity_cb(entity, attribute, old, new, kwargs):
@mmattel mmattel added the bug Something isn't working label Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant