Changeset 2593 for trunk/components/tools/OmeroPy/src/omero/__init__.py
- Timestamp:
- 07/05/08 22:16:05 (5 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/components/tools/OmeroPy/src/omero/__init__.py
r2592 r2593 18 18 from omero_ext import pysys 19 19 import omero_Constants_ice 20 import uuid 20 21 21 22 class client(object): … … 31 32 32 33 self.sf = None 33 self.ic = None 34 ic = Ice.initialize(args,id) 35 if not ic: 34 self.ic = Ice.initialize(args,id) 35 if not self.ic: 36 36 raise ClientError("Improper initialization") 37 # Register Object Factory 37 38 self.of = ObjectFactory() 38 self.of.registerObjectFactory(ic) 39 self.ic = ic 40 self.close_on_destroy = True 41 42 def closeOnDestroy(self): 43 """ 44 Closes the blitz session when destroyConnection() is called on exit. 45 This prevents other clients from attaching to the same blitz session, 46 and is more secure. 47 """ 48 self.close_on_destroy = True 49 50 def detachOnDestroy(self): 51 """ 52 Prevents the blitz session from being closed when destroyConnection() 53 is called. This will allow other clients to attach to the session for 54 distribtued work. This is less secure, but in many cases valuable. 55 """ 56 self.close_on_destroy = False 39 self.of.registerObjectFactory(self.ic) 40 # Define our unique identifier (used during close/detach) 41 self.ic.getImplicitContext().put(omero.constants.CLIENT_UUID, str(uuid.uuid4())) 57 42 58 43 def __del__(self): … … 60 45 self.destroyConnection() 61 46 except exceptions.Exception, e: 62 print " Error in__del__:" + str(e.__class__)47 print "Ignoring error in client.__del__:" + str(e.__class__) 63 48 64 49 def getCommunicator(self): … … 216 201 file.close() 217 202 218 def destroyConnection(self):203 def closeSession(self): 219 204 """ 220 205 Closes the Router connection created by createSession(). Due to a bug in Ice, 221 206 only one connection is allowed per communicator, so we also destroy the communicator. 222 207 """ 208 209 # If 'sf' exists we remove it. 210 if not hasattr(self, 'sf'): 211 self.sf = None 212 223 213 # If 'ic' does not exist we don't have anything to do 224 214 if not hasattr(self, 'ic') or not self.ic: 225 215 return 226 227 if self.close_on_destroy:228 self.closeSession()229 216 230 217 prx = self.ic.getDefaultRouter() … … 250 237 self.ic = None 251 238 252 def closeSession(self):253 """254 Call close on the session (ServiceFactoryPrx) which first decrements255 the reference count. If its reference count becomes 0, then the session256 will be removed from the server.257 """258 # If 'sf' does not exist we don't have a session at all259 if not hasattr(self, 'sf'):260 return261 # But even if we do have 'sf', the connection may have been lost and 'close' will fail262 try:263 try:264 self.sf.close()265 except:266 pass267 finally:268 self.sf = None269 270 239 def _env(self, method, *args): 271 240 """ Helper method to access session environment"""
