구성 파일을 기반으로 항목을 구독하는 mqtt 클라이언트 응용 프로그램이 있습니다. 뭔가 같이 :구독을 다시로드하기위한 paho mqtt 클라이언트 인터럽트
def connectMQTT():
global Connection
Connection = Client()
Connection.on_message = handleQuery
for clientid in clientids.allIDs(): # clientids.allIDs() reads files to get this
topic = '{}/{}/Q/+'.format(Basename, clientid)
print('subscription:', topic)
Connection.subscribe(topic)
나는 같은 간단한 호출로 사용하고있다 :
def main():
connectMQTT()
Connection.loop_forever()
loop_forever
영원히 차단합니다. 그러나 clientids.allIDs()
에 의해 읽힌 정보가 시대에 뒤떨어져 있고 새로 구독해야하는 경우 다시 알려야한다는 것을 알고 싶습니다.
나는 pyinotify
가진 파일의 변화를 감지 할 수 있습니다 :
def filesChanged():
# NOT SURE WHAT TO DO HERE
def watchForChanges():
watchManager = pyinotify.WatchManager()
notifier = pyinotify.ThreadedNotifier(watchManager, FileEventHandler(eventCallback))
notifier.start()
watchManager.add_watch('/etc/my/config/dir', pyinotify.IN_CLOSE_WRITE | pyinotify.IN_DELETE)
는 기본적으로, 어떤 신호가 pyinotify 기계에서 때까지 실행 loop_forever
(또는 다른 PAHO의 MQTT 메커니즘)가 필요합니다. 그 둘을 어떻게 용접해야할지 모르겠다. 의사 코드에서, 나는 같은 것을 원한다.
def main():
signal = setup_directory_change_signal()
while True:
connectMQTT()
Connection.loop(until=signal)
Connection.disconnect()
나는 어떻게 그 효과를 내는지 잘 모르겠다.
다른'loop' 함수를 살펴 보았습니까? – hardillb
그래, 나는'loop_start()'와'loop_stop()'을 가지고 놀고 있으며, 순간에 비 스레드 알림기를 시도하고있다. 아직 운이별로 없다. –
또한 연결을 끊을 필요가 없습니다. 새 목록에 대해 diff에 가입 한 주제의 목록 만 유지하고 필요없는 이전에는 가입을 취소하고 새 항목에 가입하십시오. – hardillb