Probably found an answer thanks to @joan 's answer.
It seems like RPi.PWM can only do software PWM, but the fan requires hardware PWM to run as smooth as possible. To do hardware PWM on any GPIO pin, the pigpio daemon has to be executed, and controlled by Python. Therefore, pigpio has to be installed first and configured to be started on boot (systemd). ...
There are two fundamental differences between the two approaches.
The gpio utility (part of wiringPi)
is using hardware timed PWM.
appears to be setting a frequency of 40 kHz.
The RPi.GPIO script
is using software timed PWM.
is setting a frequency of 50 Hz.
I'd guess the frequency is the main factor.
TensorFlow will install on a RPi but it has been a bit of a nightmare. The instructions of the TensorFlow site are here, but I had to hunt around for version that would install since the standard one would not.
That said I've just tried an install on a new 8G Rpi4 using pip3 install tensorflow and it installed straight off, so I presume TensorFlow have fixed ...
This Question is too vague, asks multiple questions, is not Pi specific and is really asking how to program in Python, so will probably be closed.
However the use of Buttons and callbacks is relevant and Raspberry Pi OS includes an excellent Python library gpiozero which abstracts most of the nuts and bolts and allows effectively unlimited callbacks.
If you ...
sys.exit() or technically sys.exit(0) is designed to end the Python executable and therefore your program as well.
This is documented here for Python 3.7
Key thing to note is
so cleanup actions specified by finally clauses of try statements are honored
Hence the final message from your program in the except clause.
Using your own bespoke exception is more ...
Well, it appears it is a timing issue. I modified the code to include a loop to capture an image and finish when the size of image.data is greater than zero. Obviously slower than the first version but it appears we can't rush the pi camera.
I would prefer not to import two io/os type modules so will look into that, and also whether both forms of CAPTURE ...