Basic questions re callbacks and dispatcher

39 views
Skip to first unread message

Brandyn Webb

unread,
Jan 9, 2020, 1:16:44 PM1/9/20
to python-openzwave-discuss
Hi all,

Some general questions re. the dispatcher and callbacks:

- The callbacks are happening in a (non-main) thread.  Is this the primary/only python-openzwave thread such that I can expect all the data structures to be static while I'm in the callback?  I.e., is there any chance a Node will change while I'm in the middle of querying its attributes?

- Will anything break if I spend too much time in a callback?

- Relatedly, is there any way to lock the data structures from my main thread, such that I can query the network and node states and be assured they won't update in the middle of my query?

- Or most generally: What's the "right" way to approach this -- is there some common way to handle these issues that skirts any problems?

Lastly,

- I note the dispatcher is a global variable by default -- is it possible to pass it as a parameter when creating the Network to avoid collisions with other libraries that might also use pydispatch?  (Looking at the source code, it would seem not, but perhaps there's some trick to it?)  If not, is it just assumed that there will be no (unintentional) signal name collisions between libraries?

Thanks for any tips,

-Brandyn

Brandyn Webb

unread,
Jan 10, 2020, 2:31:50 AM1/10/20
to python-openzwave-discuss

Ok, so I've actually run into this problem in practice now.  This is from inspecting a node in the main thread while the background thread was updating it:

File ".../openzwave/node.py", line 475, in values_to_dict
   
for vid in self.values.keys():
RuntimeError: dictionary changed size during iteration


Do I have to do all object inspection in the callback thread, or is there a way to lock objects from the main thread?

Any insight appreciated here,

-Brandyn

Reply all
Reply to author
Forward
0 new messages