python - 如何在 Raspberry Pi 4 中为多个输入设备执行多线程
问题描述
我正在尝试使用 raspberry pi 4 从条形码扫描仪、称重秤和相机获取输入。我想我将为每个输入使用多线程。我分别测试了每个输入代码并且它们工作但是每当我尝试为所有它们运行多线程(现在只是条形码,称重秤和 html)时,我都会收到此错误
这个体重秤在这里
Traceback (most recent call last):
File "/usr/lib/python3.7/multiprocessing/process.py", line 297, in _bootstrap
self.run()
File "/usr/lib/python3.7/multiprocessing/process.py", line 99, in run
self._target(*self._args, **self._kwargs)
File "/home/pi/Documents/Konstant/py/cartos.py", line 142, in initiateBarcodeReader
s = readBarcode("/dev/input/event0")
File "/home/pi/Documents/Konstant/py/cartos.py", line 41, in readBarcode
dev.grab() # grab provides exclusive access to the device
File "/home/pi/.local/lib/python3.7/site-packages/evdev/device.py", line 320, in grab
_input.ioctl_EVIOCGRAB(self.fd, 1)
OSError: [Errno 16] Device or resource busy
这是我的代码的一部分,它显示了打开 html 页面以及我如何调用多线程。我不确定是否需要包括条形码扫描仪和体重秤代码,因为它们是分开工作的。如果需要,条形码扫描仪代码在这里
import eel
import os
import json
import requests
import shutil, sys
import os
from evdev import InputDevice, categorize, ecodes
import threading
import time
def openUI():
eel.init("../web")
eel.start('home.html')
if __name__ == '__main__':
ui_thread = Process(target=openUI, args=('UI opened',))
p = Process(target=startWeighingScale, args=('weighing started',))
zp = Process(target=initiateBarcodeReader, args=('Barcode called',))
ui_thread.start()
zp.start()
这是同时从这些输入中获取数据的最佳方法吗?如何修复错误?
解决方案
推荐阅读
- java - Java&Consul 无法通过有效的服务名称获取有效的 ServiceInstance 实例
- reactjs - React Native:使用 setState() 赋值
- javascript - 对对象数组进行排序的最简单方法是什么?
- python - 如何删除熊猫数据框中的错误值?
- python - 如何在 django 中传递对象?
- python - Python:获取最大的 n 位数
- unity3d - 每帧使用哪个公式进行拖动模拟?
- nginx - ffmpeg:将单个实时视频流编码为不同的分辨率并保持同步
- json - 部署aws时如何在json文件中添加gitlab用户定义的变量?
- python - 什么是 PycURL 库?