Utilizing multiple CPU cores for QR reading in Python (Pyzbar)

Viewed 154

The background:

We need to parse many QR codes. We have a main process that produces a stream of images (see example below) like a firehose. For parsing, we use Pyzbar. So far this is the fastest library we found in Python, it is also the most tolerant to low quality photos. The hardware is NVidia Jetson Nano with a 4 core CPU, 4GB memory. We have the option to deploy the main process and the QR parsing on two different Jetson Nano on a local network. Cloud is not an option, we run offline.

enter image description here

The problem:

How can we scale out parsing the QR codes to multiple CPU cores? As far as I see, multi-threading in Python is not the answer.

My (hypothetical) solution:

My idea is to run 4 identical processes to parse QR codes, use a RAM drive to distribute the work load among them. The main process would drop the images to the RAM drive. The first QR reading process that moves the image to its own folder gets the job. Treating the file system as a semaphore assumes the file move is an atomic operation and is safe against multiple hungry processes (Is it?). The parsed results can be communicated back to the main process by simple HTTP calls using the filename as ID.

The questions:

  1. Is my assumption correct concerning file move being atomic?
  2. My solution seems way overengineered to me. The same job can be done by a simple ThreadPool call in C#. Any simpler/better solution is welcome. Besides the hardware being Nvidia Jetson Nano, our hands are quite free. For keeping our codebase, dev environment and deployment process simple, sticking to Python is preferred.
0 Answers
Related