Fix infinite loop in PY3.