Parsing sensor frames from a serial port with struct
Serial devices do not respect your read boundaries. A parser has to cope with half frames, garbage and bad checksums, and resynchronise on its own.
Interpreter behaviour, memory, concurrency and talking to hardware from Python.
Serial devices do not respect your read boundaries. A parser has to cope with half frames, garbage and bad checksums, and resynchronise on its own.
Slicing bytes copies the data. When you parse a big buffer piece by piece, that adds up. memoryview slices share the memory instead.
float cannot hold 0.1 exactly, round() rounds halves to even, and Decimal(2.675) already contains the error. Three small facts that cause real reconciliation gaps.
There is an official build without the GIL, but it is a separate interpreter, most C extensions need to opt in, and your default python still has the GIL.
Python rejects a mutable default in a dataclass, but not in every place where the same mistake hides. Here is what the error protects you from.
Bouncing buttons, 3.3 V pins, software PWM jitter and a library that does not run on newer boards. The code is short. The physical side is where the time goes.
A timeout cancels the coroutine, but cancelling is a request, not a kill. Swallowing CancelledError, or shielding the wrong thing, leaves work running.
Technologies