Set Python exception when C code fails