@@ -306,8 +306,7 @@ def debug_info(self, c):
306306 '''
307307 Return some info --- useful to spot problems with refcounting
308308 '''
309- self .mutex .acquire ()
310- try :
309+ with self .mutex :
311310 result = []
312311 keys = list (self .id_to_obj .keys ())
313312 keys .sort ()
@@ -317,8 +316,6 @@ def debug_info(self, c):
317316 (ident , self .id_to_refcount [ident ],
318317 str (self .id_to_obj [ident ][0 ])[:75 ]))
319318 return '\n ' .join (result )
320- finally :
321- self .mutex .release ()
322319
323320 def number_of_objects (self , c ):
324321 '''
@@ -343,8 +340,7 @@ def create(self, c, typeid, *args, **kwds):
343340 '''
344341 Create a new shared object and return its id
345342 '''
346- self .mutex .acquire ()
347- try :
343+ with self .mutex :
348344 callable , exposed , method_to_typeid , proxytype = \
349345 self .registry [typeid ]
350346
@@ -374,8 +370,6 @@ def create(self, c, typeid, *args, **kwds):
374370 # has been created.
375371 self .incref (c , ident )
376372 return ident , tuple (exposed )
377- finally :
378- self .mutex .release ()
379373
380374 def get_methods (self , c , token ):
381375 '''
@@ -392,22 +386,16 @@ def accept_connection(self, c, name):
392386 self .serve_client (c )
393387
394388 def incref (self , c , ident ):
395- self .mutex .acquire ()
396- try :
389+ with self .mutex :
397390 self .id_to_refcount [ident ] += 1
398- finally :
399- self .mutex .release ()
400391
401392 def decref (self , c , ident ):
402- self .mutex .acquire ()
403- try :
393+ with self .mutex :
404394 assert self .id_to_refcount [ident ] >= 1
405395 self .id_to_refcount [ident ] -= 1
406396 if self .id_to_refcount [ident ] == 0 :
407397 del self .id_to_obj [ident ], self .id_to_refcount [ident ]
408398 util .debug ('disposing of obj with id %r' , ident )
409- finally :
410- self .mutex .release ()
411399
412400#
413401# Class to represent state of a manager
@@ -671,14 +659,11 @@ class BaseProxy(object):
671659
672660 def __init__ (self , token , serializer , manager = None ,
673661 authkey = None , exposed = None , incref = True ):
674- BaseProxy ._mutex .acquire ()
675- try :
662+ with BaseProxy ._mutex :
676663 tls_idset = BaseProxy ._address_to_local .get (token .address , None )
677664 if tls_idset is None :
678665 tls_idset = util .ForkAwareLocal (), ProcessLocalSet ()
679666 BaseProxy ._address_to_local [token .address ] = tls_idset
680- finally :
681- BaseProxy ._mutex .release ()
682667
683668 # self._tls is used to record the connection used by this
684669 # thread to communicate with the manager at token.address
0 commit comments