move timeout logic to python