Page 1 of 1

Closing a Session using the API

PostPosted: Tue Oct 05, 2010 3:03 pm
by icaoberg
I have one question. Say I have a script that created client, session and gateway objects. Does the method client.closeSession close the three of them cleanly or should I run gateway.close and session.close before client.closeSession? :geek:

Re: Closing a Session using the API

PostPosted: Tue Oct 05, 2010 3:19 pm
by jmoore
I'd suggest the following:

Code: Select all
try:
    client = omero.script.client(...)
    gateway = client.sf.createGateway()
    try:
        ... do work
    finally:
        gateway.close()
finally:
    client.closeSession()


closeSession() is the session level close you are looking for. Notice that http://hudson.openmicroscopy.org.uk/job/OMERO/javadoc/slice2html/omero/api/ServiceFactory.html#close is deprecated.

Closing the gateway before closing the session is mostly good form, but there's also an element of conserving resources. Even though you call closeSession, the server has an extra reference to your session so that it can retrieve your values, and so the session won't truly be removed until the reference count goes to zero. So always, always close services like gateway when possible.

~Josh.