We're Hiring!

Closing a Session using the API

General and open developer discussion about using OMERO APIs from C++, Java, Python, Matlab and more! Please new questions at https://forum.image.sc/tags/omero
Please note:
Historical discussions about OMERO. Please look for and ask new questions at https://forum.image.sc/tags/omero

If you are having trouble with custom code, please provide a link to a public repository, ideally GitHub.

Closing a Session using the API

Postby icaoberg » Tue Oct 05, 2010 3:03 pm

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:
icaoberg
 
Posts: 145
Joined: Fri Sep 17, 2010 9:05 pm
Location: Pittsburgh, PA

Re: Closing a Session using the API

Postby jmoore » Tue Oct 05, 2010 3:19 pm

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.
User avatar
jmoore
Site Admin
 
Posts: 1591
Joined: Fri May 22, 2009 1:29 pm
Location: Germany


Return to Developer Discussion

Who is online

Users browsing this forum: Google [Bot] and 0 guests