求助!关于使用Blinker-py库发送实时数据时出现的问题
本帖最后由 yinbing 于 2022-6-20 20:39 编辑各位大神,我在树莓派4B上运行blinker-py库自带的实时数据示例(代码见图1)时,出现了图2所示报错,然后虽然程序仍能连上服务器,但无法响应APP实时数据请求(key已经检查过,设置正确)。我对python还不是非常熟悉,请大神们帮帮忙看看该如何解决这个问题。
环境:树莓派4B、raspberrypi os 32bit lite(debian11 bullseye)、python3.9。
图1示例代码(文件名:blinker_realtime_test.py):
# -*- coding: utf-8 -*-
"""
实时数据
"""
__author__ = 'stao'
import random
from blinker import Device
def generate_data():
return random.randint(1, 100)
async def realtime_func(keys):
print("realtime func received {0}".format(keys))
for key in keys:
if key == "num-hid":
await device.sendRtData(key, generate_data)
elif key == "num-tid":
await device.sendRtData(key, generate_data)
device = Device("xxxxxxxxx", realtime_func=realtime_func)
if __name__ == '__main__':
device.run()
图2bash shell 报错:
pi@raspberrypi:~/ydyp_dir/src_pi $ python blinker_realtime_test.py
Exception in thread Thread-5:
Traceback (most recent call last):
File "/usr/lib/python3.9/threading.py", line 954, in _bootstrap_inner
self.run()
File "/usr/lib/python3.9/threading.py", line 892, in run
self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.9/dist-packages/blinker/device.py", line 170, in scheduler_run
self.scheduler.start()
File "/usr/local/lib/python3.9/dist-packages/apscheduler/schedulers/background.py", line 35, in start
BaseScheduler.start(self, *args, **kwargs)
File "/usr/local/lib/python3.9/dist-packages/apscheduler/schedulers/base.py", line 150, in start
self.add_executor(self._create_default_executor(), 'default')
File "/usr/local/lib/python3.9/dist-packages/apscheduler/schedulers/base.py", line 762, in _create_default_executor
return ThreadPoolExecutor()
File "/usr/local/lib/python3.9/dist-packages/apscheduler/executors/pool.py", line 53, in __init__
pool = concurrent.futures.ThreadPoolExecutor(int(max_workers), **pool_kwargs)
File "/usr/lib/python3.9/concurrent/futures/__init__.py", line 49, in __getattr__
from .thread import ThreadPoolExecutor as te
ImportError: cannot import name 'ThreadPoolExecutor' from partially initialized module 'concurrent.futures.thread' (most likely due to a circular import) (/usr/lib/python3.9/concurrent/futures/thread.py)
2022-06-20 20:17:16.690 | SUCCESS| blinker.device:device_init:225 - Device auth successful...
2022-06-20 20:17:16.692 | INFO | blinker.device:_cloud_heartbeat:248 - Send cloud heartbeat
2022-06-20 20:17:16.703 | INFO | blinker.httpclient:cloud_heartbeat:128 - http cloud heartbeat
2022-06-20 20:17:16.990 | INFO | blinker.mqttclient:_on_connect:46 - Connect to broker from mqtt
2022-06-20 20:17:16.991 | SUCCESS| blinker.mqttclient:_on_connect:48 - Broker connected...
2022-06-20 20:17:16.993 | SUCCESS| blinker.device:_receiver:384 - Receiver ready...
页:
[1]