Changeset 2592 for trunk/components/tools/OmeroPy/src/omero/__init__.py
- Timestamp:
- 07/05/08 22:16:04 (5 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/components/tools/OmeroPy/src/omero/__init__.py
r2396 r2592 11 11 """ 12 12 13 import exceptions 13 import exceptions, traceback 14 14 import Ice, Glacier2 15 15 import api … … 21 21 class client(object): 22 22 """ 23 Central blitz entry point 23 Central blitz entry point. Currently useful for a single session, after closing the 24 connection, create another instance. 24 25 25 26 Typical usage includes: … … 37 38 self.of.registerObjectFactory(ic) 38 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 """ 39 56 self.close_on_destroy = False 40 57 41 def closeOnDestroy(self):42 self.close_on_destroy = True43 44 58 def __del__(self): 45 if self.close_on_destroy: 46 self.closeSession() 47 if self.ic: 48 try: 49 self.ic.destroy() 50 except (), msg: 51 pysys.stderr.write("Ice exception while destroying communicator:") 52 pysys.stderr.write(msg) 53 self.ic = None 59 try: 60 self.destroyConnection() 61 except exceptions.Exception, e: 62 print "Error in __del__:" + str(e.__class__) 54 63 55 64 def getCommunicator(self): … … 207 216 file.close() 208 217 218 def destroyConnection(self): 219 """ 220 Closes the Router connection created by createSession(). Due to a bug in Ice, 221 only one connection is allowed per communicator, so we also destroy the communicator. 222 """ 223 # If 'ic' does not exist we don't have anything to do 224 if not hasattr(self, 'ic') or not self.ic: 225 return 226 227 if self.close_on_destroy: 228 self.closeSession() 229 230 prx = self.ic.getDefaultRouter() 231 router = Glacier2.RouterPrx.checkedCast(prx) 232 233 # Now destroy the actual session if possible, 234 # which will always trigger an exception, 235 # regardless of actually being connected or not 236 if router: 237 try: 238 router.destroySession() 239 except exceptions.Exception, e: 240 pass 241 # SNEE happens if we call sf.close() before 242 # calling destroySession(). CLE happens since 243 # we are disconnecting 244 245 try: 246 self.ic.destroy() 247 except (), msg: 248 pysys.stderr.write("Ice exception while destroying communicator:") 249 pysys.stderr.write(msg) 250 self.ic = None 251 209 252 def closeSession(self): 253 """ 254 Call close on the session (ServiceFactoryPrx) which first decrements 255 the reference count. If its reference count becomes 0, then the session 256 will be removed from the server. 257 """ 210 258 # If 'sf' does not exist we don't have a session at all 211 259 if not hasattr(self, 'sf'): … … 219 267 finally: 220 268 self.sf = None 221 # Now destroy the actual session, which will always trigger an exception, regardless of222 # actually being connected or not223 prx = self.ic.getDefaultRouter()224 router = Glacier2.RouterPrx.checkedCast(prx)225 try:226 router.destroySession()227 except Ice.ConnectionLostException:228 pass229 269 230 270 def _env(self, method, *args):
