RuntimeError: cannot set daemon status of active thread
RuntimeError: cannot set daemon status of active thread
我正在尝试 运行 在 on_message
回调时并行进行一些测试。当我的 on_message
回调被调用时,基于一些消息,我创建了一个线程来 运行 一些测试并将其设置为守护线程。当我 运行 时,我得到这个 运行 时间错误。
"cannot set daemon status of active thread".
#this is the callback attached to paho.mqtt.client client.on_message = self.on_message
def on_message(self, client, userdata, msg):
if msg.topic.startswith("hello/"):
#set some vlaues
elif msg.topic.startswith("data/"):
#set some vlaues
elif msg.topic.startswith("test/"):
value = msg.payload.decode("utf-8")
lst = value.split('-')
test = Test()
test._value = lstr[0]
t = Thread(target = test.callmethod,args=(lst[1]))
t.start()
t.setDaemon(True)
Exception in thread Thread-2:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/usr/local/lib/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
TypeError: mymethod() takes 2 positional arguments but 10 were given
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/usr/local/lib/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.6/site-packages/paho_mqtt-1.3.1-py3.6.egg/paho/mqtt/client.py", line 2650, in _thread_main
self.loop_forever(retry_first_connection=True)
File "/usr/local/lib/python3.6/site-packages/paho_mqtt-1.3.1-py3.6.egg/paho/mqtt/client.py", line 1481, in loop_forever
rc = self.loop(timeout, max_packets)
File "/usr/local/lib/python3.6/site-packages/paho_mqtt-1.3.1-py3.6.egg/paho/mqtt/client.py", line 1003, in loop
rc = self.loop_read(max_packets)
File "/usr/local/lib/python3.6/site-packages/paho_mqtt-1.3.1-py3.6.egg/paho/mqtt/client.py", line 1284, in loop_read
rc = self._packet_read()
File "/usr/local/lib/python3.6/site-packages/paho_mqtt-1.3.1-py3.6.egg/paho/mqtt/client.py", line 1849, in _packet_read
rc = self._packet_handle()
File "/usr/local/lib/python3.6/site-packages/paho_mqtt-1.3.1-py3.6.egg/paho/mqtt/client.py", line 2305, in _packet_handle
return self._handle_publish()
File "/usr/local/lib/python3.6/site-packages/paho_mqtt-1.3.1-py3.6.egg/paho/mqtt/client.py", line 2500, in _handle_publish
self._handle_on_message(message)
File "/usr/local/lib/python3.6/site-packages/paho_mqtt-1.3.1-py3.6.egg/paho/mqtt/client.py", line 2647, in _handle_on_message
self.on_message(self, self._userdata, message)
File "/usr/local/lib/python3.6/site-packages/myproject-0.0.1-py3.6.egg/subscribe/client.py", line 60, in on_message
t.setDaemon(True)
File "/usr/local/lib/python3.6/threading.py", line 1148, in setDaemon
self.daemon = daemonic
File "/usr/local/lib/python3.6/threading.py", line 1141, in daemon
raise RuntimeError("cannot set daemon status of active thread")
RuntimeError: cannot set daemon status of active thread
setDaemon
应该在start
之前使用:
t = Thread(target = test.callmethod,args=(lst[1]))
t.setDaemon(True) # first
t.start() # second
我正在尝试 运行 在 on_message
回调时并行进行一些测试。当我的 on_message
回调被调用时,基于一些消息,我创建了一个线程来 运行 一些测试并将其设置为守护线程。当我 运行 时,我得到这个 运行 时间错误。
"cannot set daemon status of active thread".
#this is the callback attached to paho.mqtt.client client.on_message = self.on_message
def on_message(self, client, userdata, msg):
if msg.topic.startswith("hello/"):
#set some vlaues
elif msg.topic.startswith("data/"):
#set some vlaues
elif msg.topic.startswith("test/"):
value = msg.payload.decode("utf-8")
lst = value.split('-')
test = Test()
test._value = lstr[0]
t = Thread(target = test.callmethod,args=(lst[1]))
t.start()
t.setDaemon(True)
Exception in thread Thread-2:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/usr/local/lib/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
TypeError: mymethod() takes 2 positional arguments but 10 were given
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/usr/local/lib/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.6/site-packages/paho_mqtt-1.3.1-py3.6.egg/paho/mqtt/client.py", line 2650, in _thread_main
self.loop_forever(retry_first_connection=True)
File "/usr/local/lib/python3.6/site-packages/paho_mqtt-1.3.1-py3.6.egg/paho/mqtt/client.py", line 1481, in loop_forever
rc = self.loop(timeout, max_packets)
File "/usr/local/lib/python3.6/site-packages/paho_mqtt-1.3.1-py3.6.egg/paho/mqtt/client.py", line 1003, in loop
rc = self.loop_read(max_packets)
File "/usr/local/lib/python3.6/site-packages/paho_mqtt-1.3.1-py3.6.egg/paho/mqtt/client.py", line 1284, in loop_read
rc = self._packet_read()
File "/usr/local/lib/python3.6/site-packages/paho_mqtt-1.3.1-py3.6.egg/paho/mqtt/client.py", line 1849, in _packet_read
rc = self._packet_handle()
File "/usr/local/lib/python3.6/site-packages/paho_mqtt-1.3.1-py3.6.egg/paho/mqtt/client.py", line 2305, in _packet_handle
return self._handle_publish()
File "/usr/local/lib/python3.6/site-packages/paho_mqtt-1.3.1-py3.6.egg/paho/mqtt/client.py", line 2500, in _handle_publish
self._handle_on_message(message)
File "/usr/local/lib/python3.6/site-packages/paho_mqtt-1.3.1-py3.6.egg/paho/mqtt/client.py", line 2647, in _handle_on_message
self.on_message(self, self._userdata, message)
File "/usr/local/lib/python3.6/site-packages/myproject-0.0.1-py3.6.egg/subscribe/client.py", line 60, in on_message
t.setDaemon(True)
File "/usr/local/lib/python3.6/threading.py", line 1148, in setDaemon
self.daemon = daemonic
File "/usr/local/lib/python3.6/threading.py", line 1141, in daemon
raise RuntimeError("cannot set daemon status of active thread")
RuntimeError: cannot set daemon status of active thread
setDaemon
应该在start
之前使用:
t = Thread(target = test.callmethod,args=(lst[1]))
t.setDaemon(True) # first
t.start() # second