1

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?

5
  • Why have you removed the import statements - they help us see which packages you are referring to. Commented Dec 17, 2020 at 9:22
  • @MarkSetchell I've added the packages Commented Dec 17, 2020 at 11:37
  • What actual input devices do the barcode/scale use - they aren’t on the same device, are they? Commented Dec 19, 2020 at 15:32
  • @barny I've added it the devices. They are separate devices Commented Dec 19, 2020 at 17:50
  • In general, you should extract and provide a minimal reproducible example. Also, note that a process and a thread are two different beasts, so that might explain your problems. Commented Dec 19, 2020 at 18:30

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.