Avoid python crash mentioned in issue #331