我的目标是从6个sensortag2中获得加速度计,磁力计,陀螺仪的读数。由于阅读需要太多时间才能打印,因此我想使用 multiprocessing.Pool 。但是,当我尝试为pool.map函数添加参数时,就会出现问题。
from bluepy.sensortag import SensorTag
SENSORTAG_ADDRESS = "24:71:89:XX:XX:XX" #Mac address of IMU1
SENSORTAG_ADDRESS2 = "24:71:89:XX:DC:XX" #Mac address of IMU2
SENSORTAG_ADDRESS3 = "24:71:XX:XX:XX:XX" #Mac address of IMU3
def enable_sensors(tag):
"""Enable sensors so that readings can be made."""
tag.accelerometer.enable()
tag.magnetometer.enable()
tag.gyroscope.enable()
time.sleep(1.0) #some sensore eg.acceleromete takes time to initiate
def readtag(tag):
readings = get_readings(tag)
T=datetime.datetime.now()
return readings, T
if __name__ == '__main__':
tag = SensorTag(SENSORTAG_ADDRESS)
tag2= SensorTag(SENSORTAG_ADDRESS2)
tag3= SensorTag(SENSORTAG_ADDRESS3)
enable_sensors(tag)
enable_sensors(tag1)
enable_sensors(tag2)
pool=multiprocessing.Pool(processes=3)
res=pool.map(readtag, [tag1,tag2,tag3])
运行脚本时,出现错误:
cPickle.UnpickleableError:无法腌制类型为“ select.poll”的对象。
我尝试了 print(tag1) 并输出:位于0x7f5b0ad5a098 >的<< strong> bluepy.sensortag.SensorTag实例>。 谁能帮忙吗?