Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [paho-dev] Status of paho-mqtt for python

Peter Silva via paho-dev <paho-dev@xxxxxxxxxxx> writes:

> I normally use ubuntu packages, but I wanted to make a PR for a feature I
> need.  To start work, I need to get a working
> source tree.  Is the master branch on github supposed to be usable?

Of course it should be....

> I cloned the master branch of
> https://github.com/eclipse/paho.mqtt.python and the try using it by
> installing with "pip3 install -e . " on my linux workstation.

>
> I try using it in my application,
>     self.reconnect()
>   File "/home/peter/src/paho.mqtt.python/src/paho/mqtt/client.py", line
> 1045, in reconnect
>     on_pre_connect = self.on_pre_connect
>   File "/home/peter/src/paho.mqtt.python/src/paho/mqtt/client.py", line
> 1863, in on_pre_connect
>     return self._on_pre_connect
> AttributeError: 'Client' object has no attribute '_on_pre_connect'. Did you
> mean: 'on_pre_connect'?

I see this too.


With some excessive punctuation, on
  NetBSD 10 amd64
  python 3.10

I get

SKIPPED [21] .eggs/pytest-7.4.2-py3.11.egg/_pytest/unittest.py:371: paho.mqtt.testing not present.
==== 26 failed, 18 passed, 21 skipped, 8 warnings in 251.32s (0:04:11) ====

> Does this make sense?  Should I be working from some other source?

This is the right repo, according to starting with the paho homepage.



If I back up to the v1.6.1 tag:

  commit a4cb435ca2864d073ea3e0e18b0407e4bbe85b16 (origin/master, origin/HEAD, master)
  Author: Roger Light <roger@xxxxxxxxxx>
  Date:   Sat Jan 21 00:12:33 2023 +0000

      Add on_pre_connect() callback

      This is called immediately before a connection attempt is made.

  commit 9782ab81fe7ee3a05e74c7f3e1d03d5611ea4be4 (HEAD, tag: v1.6.1)
  Merge: 6dfdeba 1f3cd09
  Author: Roger A. Light <roger@xxxxxxxxxx>
  Date:   Thu Oct 21 11:05:05 2021 +0100

      Merge branch '1.6.x'

then tests show (again punctuation remediated):

SKIPPED [21] .eggs/pytest-7.4.2-py3.11.egg/_pytest/unittest.py:371: paho.mqtt.testing not present.
==== 44 passed, 21 skipped in 11.25s ====


I think the addition of the preconnect callback has a few issues.
With this, it passes:


diff --git a/src/paho/mqtt/client.py b/src/paho/mqtt/client.py
index 54405a4..5515af7 100644
--- a/src/paho/mqtt/client.py
+++ b/src/paho/mqtt/client.py
@@ -615,6 +615,7 @@ class Client(object):
         self._registered_write = False
         # No default callbacks
         self._on_log = None
+        self._on_pre_connect = None
         self._on_connect = None
         self._on_connect_fail = None
         self._on_subscribe = None
@@ -1881,7 +1882,7 @@ class Client(object):
 
     def pre_connect_callback(self):
         def decorator(func):
-            self.on_pre_connect = func
+            self._on_pre_connect = func
             return func
         return decorator
 


Back to the top