Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > de.comp.lang.python > #5986

[Python-de] Re: paho-mqtt und vorgegebene Callback-Funktionen in einer Klasse.

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Hartmut Goebel <h.goebel@goebel-consult.de>
Newsgroups de.comp.lang.python
Subject [Python-de] Re: paho-mqtt und vorgegebene Callback-Funktionen in einer Klasse.
Date Sun, 11 Jun 2023 20:52:56 +0200
Organization Goebel Consult
Lines 32
Message-ID <e34fbaa8-14b6-b8df-b2f9-40b772fc8352@goebel-consult.de> (permalink)
References <u64v9c$2041$1@news1.tnib.de>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding base64
X-Trace news.uni-berlin.de s8gp9/kXug2dK9hdVExC9w9N2+kNhL4qvbJZ2lXuvnBA==
Authentication-Results mail.python.org; dkim=none reason="no signature"; dkim-adsp=none (unprotected policy); dkim-atps=neutral
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.2
Content-Language de-DE, en-US
In-Reply-To <u64v9c$2041$1@news1.tnib.de>
X-Provags-ID V03:K1:2tab/Lq4QoSuY9Mo1UXDcFMHrjhs6NvzNtssd52peHeZj9WjjqW IwDQ06j8XyItnnXK8YU+8MF6ntKFXfsgmZL8uG7eJIqVpoRnlrwPXhbZKrPiKzHQMTUnL0f XSBlNtxGig0siww8Qc0JMDjJ4LzSdCFQZ/XZKEJKUaK0Wn0wL3oK2xJ5i5e62wlHWxvTYx7 xDmF+6YkjVp+VGp+eqBRQ==
X-Spam-Flag NO
UI-OutboundReport notjunk:1;M01:P0:7X8gyQF7OWg=;TEu0Jp512dLVO1/nJEHJPwaZ/6T MRy/GBhuKgY8AVqIq/KJwv75s2rk3++5hwuH6vcn88idVzBBiibs+SuQq2mpYdS/ccHcoAPZk rGxbhZI7xOx2ZPTHk+nqzhNbtLCtSZRGNpAw3pQ21knMN3d64IlFYOo/qJPtUNX/daHOLf3ih HMteNJ/VqT3353hsnwU6kmtfApklxZF+/BgWg28noZ8wvRsORNKsTBrM8DJVgVsQugoHXfLh+ 6fB4sq5m+xi3GWGAtv8Rn33zjpgGFq6Wf/+zJdQqxSRJ1kuNRWDJEicDwrSAD3NzQICbUwWRM 7KS6D4Iv9zPPzLdQbIbnzyz+Md3TDvOiKThDi8dKwM+vwADjRBr6+AXheWevHHXlRIa0guE76 j/ni9ucYxhRTBf/dnUjDKD94SSk+d3DI3+HDjI0tXELyJlon/x+9OHnz1RHukcPtSesqncfll XEGzQhLMW7lJKdlFKwX2SEPFUSJnAgP1wPeVBU8ex7p9l8F2Bg/UXifcCMJD50en3XE0sp63Q 8kzp6jqRI+H4TI6VhP+dhQOPW+JsBnuKlG7y6qNI73Ie9m3PQ5YCu+DBj+dBXhFQVGET+8ajL 3qFxz4asbMKeCmVgKaQ/rAU1kI1qeCM1h1ihqpn6Qr3m8RULfO6sMyo5rUTGtiuTDtvJWuGJW amhrkEDsQn4QROmtYNOg1wGhsPau6WwuMIhWKkOFgQ==
Message-ID-Hash XTNASXU2IWVQGMMMBYPQBMQ3YUOOOHCG
X-Message-ID-Hash XTNASXU2IWVQGMMMBYPQBMQ3YUOOOHCG
X-MailFrom h.goebel@goebel-consult.de
X-Mailman-Rule-Misses dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-python-de.python.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header
X-Content-Filtered-By Mailman/MimeDel 3.3.9b1
X-Mailman-Version 3.3.9b1
Precedence list
List-Id Die Deutsche Python Mailingliste <python-de.python.org>
Archived-At <https://mail.python.org/archives/list/python-de@python.org/message/XTNASXU2IWVQGMMMBYPQBMQ3YUOOOHCG/>
List-Archive <https://mail.python.org/archives/list/python-de@python.org/>
List-Help <mailto:python-de-request@python.org?subject=help>
List-Owner <mailto:python-de-owner@python.org>
List-Post <mailto:python-de@python.org>
List-Subscribe <mailto:python-de-join@python.org>
List-Unsubscribe <mailto:python-de-leave@python.org>
Xref csiph.com de.comp.lang.python:5986

Show key headers only | View raw


Hallo,

ich kenne die Diskussion von vor einem halbe Jahr nicht, aber mir fällt 
folgendes auf:

Am 11.06.23 um 19:12 schrieb Marc Haber:
> |    def on_connect(self, client, userdata, flags, rcode):
> |        client.subscribe('tele/wama/SENSOR')
> [_]
> |        client = mqtt.Client()
> |        client.on_connect = on_connect

Diese Zeile muss lauten:

         client.on_connect =*self.*on_connect

Es wundert mich, dass Dein Code überhaupt funktioniert, denn 
"on_connect" ist nicht definiert. Oder hast Du das nur zu viel gekürzt?!

> Leider haben die beiden Callbackfunktionen von paho eine vorgegebene
> Signatur und können deswegen keine Methoden des ApplianceMonitor sein.

Hmm, Ich habe eben folgendes probiert, und das klappt (X.on_connect wird 
wie erwartet mit der Instanz von ApplianceMonitor als ersten Argument 
und den anderen vier danach aufgerufen):

class Client:
     def doit(self):
         self.on_connect(self, 2, 3, 4)

class ApplianceMonitor:
     def on_connect(self, client, userdata, flags, rcode):
         print(self, client, userdata, flags, rcode)

     def main(self):
         c = Client()
         c.on_connect = self.on_connect
         c.doit()

ApplianceMonitor().main()

Andernfalls verstehe ich nicht, was Deine Frage ist.


-- 
Schönen Gruß
Hartmut Goebel
Dipl.-Informatiker (univ), CISSP, CSSLP, ISO 27001 Lead Implementer
Information Security Management, Security Governance, Secure Software 
Development

Goebel Consult, Landshut
http://www.goebel-consult.de

Blog: 
https://www.goebel-consult.de/blog/2021/debugging-python-_frozen_importlib/
Kolumne: 
https://www.goebel-consult.de/blog/cissp-gefluester/2012-04-compliance-bringt-keine-sicherheit/ 

Back to de.comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

paho-mqtt und vorgegebene Callback-Funktionen in einer Klasse. Marc Haber <mh+usenetspam1118@zugschl.us> - 2023-06-11 19:12 +0200
  [Python-de] Re: paho-mqtt und vorgegebene Callback-Funktionen in einer Klasse. Hartmut Goebel <h.goebel@goebel-consult.de> - 2023-06-11 20:52 +0200
    Re: [Python-de] Re: paho-mqtt und vorgegebene Callback-Funktionen in einer Klasse. Marc Haber <mh+usenetspam1118@zugschl.us> - 2023-06-11 21:41 +0200
      Re: [Python-de] Re: paho-mqtt und vorgegebene Callback-Funktionen in einer Klasse. "Peter J. Holzer" <hjp-usenet3@hjp.at> - 2023-06-11 22:06 +0200
      [Python-de] Re: paho-mqtt und vorgegebene Callback-Funktionen in einer Klasse. Hartmut Goebel <h.goebel@goebel-consult.de> - 2023-06-11 22:09 +0200
  [Python-de] Re: paho-mqtt und vorgegebene Callback-Funktionen in einer Klasse. Stefan Clauß <st_clauss@gmx.de> - 2023-06-21 14:01 +0200

csiph-web