gh-7053: check for OSError during rehashx()

Fix for https://github.com/ipython/ipython/issues/7053