Fix issue #7282

Hi, this is my first pull request.

It's a simple replacement of ip.set_hook with atexit.register. Note that the IPython session (`ip`), supplied as the second argument to `atexit.register` is the argument that is supplied to the lambda function.