perf python: Use exception to propagate errors