I am trying to get input from a barcode scanner, weighing scale and cameras using raspberry pi 4. I figured i'll use multithreading for each of the inputs. I tested each input code separately and they worked but whenever i try to run a multithreading for all of them (just barcode, weighing scale and html for now) I get this error
I am using this barcode scanner here
and this weight scale here
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
This is part of my code that shows opening the html page and how I call the multithreading. I'm not sure if including the barcode scanner and weight scale code is necessary since they work separately. Barcode scanner code is here if needed
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()
Is this the best approach to simultaneously get data from these inputs and how can I fix the error?