atoti.Session.close()#

Session.close()#

Close this session and free all associated resources.

The session cannot be used after calling this method.

Closing a session frees its port so it can be reused by another session or another process.

This method is called by the __del__() method so garbage collected sessions will automatically be closed. Python synchronously garbage collects objects as soon as their last (hard) reference is lost. In a notebook, it is thus possible to run the following cell multiple times without encountering a “port already in use” error:

# (Re)assigning the `session` variable to garbage collect previous reference (if any).
session = None
# If a previous `session` was using port 1337, it is now free to use again (unless another process just took it).
session = tt.Session.start(tt.SessionConfig(port=1337))

Note

In a notebook, evaluating/printing an object creates long lasting references to it preventing the object from being garbage collected. The pattern shown above will thus only work if the session object was not used as the last expression of a cell.