eclipse / paho.mqtt.python

paho.mqtt.python
Other
2.19k stars 721 forks source link

Control Over will_set() Calls After loop_start() #658

Closed alexander-ryker closed 1 year ago

alexander-ryker commented 2 years ago

After calling loop_start(), the MQTT client module will handle the necessary networking and reconnect logic in its own thread. To my knowledge, however, once loop_forever() is running in its own thread (as a result of the loop_start() call) there is no way to call will_set() with a new Node death payload before the client module calls connect() as needed.

Could a callback be added as an optional argument to loop_start() that would allow custom logic to be executed immediately prior to the connect() call?

alexander-ryker commented 2 years ago

Update: We were able to work around this by placing our will_set() call in the on_disconnect() callback. I will leave it to the Eclipse team to decide if this issue should be kept or closed.

ralight commented 1 year ago

I have added an on_pre_connect() callback which should solve this problem for you. It will be part of the next feature release.