diff --git a/components/tools/OmeroPy/src/omero/util/sessions.py b/components/tools/OmeroPy/src/omero/util/sessions.py index 7fa8b415f3b..a5e7aa8d4ed 100644 --- a/components/tools/OmeroPy/src/omero/util/sessions.py +++ b/components/tools/OmeroPy/src/omero/util/sessions.py @@ -342,24 +342,28 @@ def create(self, name, pasw, props, new=True, set_current=True, sudo=None): client = omero.client(props) client.setAgent("OMERO.sessions") - if sudo is not None: - sf = client.createSession(sudo, pasw) - principal = omero.sys.Principal() - principal.name = name - principal.group = props.get("omero.group", None) - principal.eventType = "User" - - # Retrieve the default time to idle value - uuid = sf.ice_getIdentity().name - sess = sf.getSessionService().getSession(uuid) - timeToIdle = sess.getTimeToIdle().getValue() - - sess = sf.getSessionService().createSessionWithTimeouts( - principal, 0, timeToIdle) - client.closeSession() - sf = client.joinSession(sess.getUuid().getValue()) - else: - sf = client.createSession(name, pasw) + try: + if sudo is not None: + sf = client.createSession(sudo, pasw) + principal = omero.sys.Principal() + principal.name = name + principal.group = props.get("omero.group", None) + principal.eventType = "User" + + # Retrieve the default time to idle value + uuid = sf.ice_getIdentity().name + sess = sf.getSessionService().getSession(uuid) + timeToIdle = sess.getTimeToIdle().getValue() + + sess = sf.getSessionService().createSessionWithTimeouts( + principal, 0, timeToIdle) + client.closeSession() + sf = client.joinSession(sess.getUuid().getValue()) + else: + sf = client.createSession(name, pasw) + except: + client.__del__() + raise ec = sf.getAdminService().getEventContext() uuid = sf.ice_getIdentity().name