Skip to content
Advertisement

Quit Python QR Scanner when no code is detected but keep running while processing the code

I’m creating a python script that scans QR codes, and then processes the info in the code. The python-script will launch every few seconds via a timer in systemd on RBPI, but while scanning for a code – if no code has been detected in 5 seconds, the script should terminate. However, if a code is detected, the processing should keep running, and the script should only exit when the processing is done.

This is my code:

JavaScript

So when no code is detected, the timeout of 5 should be ok, but should be ignored while running the while-loop inside decoder(image)

Advertisement

Answer

After searching on this for the day, and with Yves’ comment on the question, I came to the conclusion that I was working the wrong way around. So now I added a global Timer, which get canceled if the processing of the QR code gets started.

Now my code looks like this, and it seems to work. Would love to hear it if there is a better way, or if this use of globals is bad practise.

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement