Page 1 of 1

Python plugin wait/sleep challenge

Posted: Monday 18 February 2019 20:53
by neptunus
Hello,

I needs some tips to send me in the right direction. I'm working on a plugin for one of my modbus sensors. I have a challenge that between messages there is unfortunately a 100 ms delay needed. I want to write this plugin by using the python plug framework. On this page you will find the following: "Waiting or sleeping. Plugins are single threaded so the whole plugin system will wait."

Obviously this is not what I want. Does anyone have tips on how to properly solve this with the python plug framework for Domoticz?

Re: Python plugin waity/sleep challenge

Posted: Tuesday 19 February 2019 12:10
by Dnpwwo
@neptunus,

If you post your plugin source people can comment but generally you have 2 choices to avoid stalling the Python Framework:
  • Use the built in connection objects for reading and writing (recommended)
  • If you are using an existing library to do a lot of work for you you could consider running it on a separate thread. Depends on your Python coding skills.
but if the 100ms is pretty constant I wouldn't worry about it, its not a significant delay.

Re: Python plugin waity/sleep challenge

Posted: Tuesday 19 February 2019 13:56
by neptunus
Dnpwwo wrote: Tuesday 19 February 2019 12:10 @neptunus,

If you post your plugin source people can comment but generally you have 2 choices to avoid stalling the Python Framework:
  • Use the built in connection objects for reading and writing (recommended)
  • If you are using an existing library to do a lot of work for you you could consider running it on a separate thread. Depends on your Python coding skills.
but if the 100ms is pretty constant I wouldn't worry about it, its not a significant delay.
@Dnpwwo
I have multiply messaged that need the 100ms delay. To be precise I need to read 86 variables of the slave device. Did means a delay of ~9 seconds for one slave. I need to read 3 of them, 26 seconds significant a delay. For now, there is no point in sharing the code (btw. I would not be a problem to do so at a later moment). Must first have a good idea to solve this properly.


I will study connection objects. Is there a good example of how to use the connection object in which external hardware is read from another python script?

Re: Python plugin wait/sleep challenge

Posted: Wednesday 20 February 2019 23:39
by Dnpwwo
@neptunus,

The framework can communicate with a lot of things, serial ports, TCP/IP, UDP/IP etc so the questions is how do you connect to your Python script not can it be done.

@MichealCervantez,

What are you trying to do with it? (or is this clickbait?)