@@ -728,31 +728,25 @@ def get_server(self):
728
728
def SharedMemory (self , size ):
729
729
"""Returns a new SharedMemory instance with the specified size in
730
730
bytes, to be tracked by the manager."""
731
- conn = self ._Client (self ._address , authkey = self ._authkey )
732
- try :
731
+ with self ._Client (self ._address , authkey = self ._authkey ) as conn :
733
732
sms = SharedMemory (None , flags = O_CREX , size = size )
734
733
try :
735
734
dispatch (conn , None , 'track_segment' , (sms .name ,))
736
735
except BaseException as e :
737
736
sms .unlink ()
738
737
raise e
739
- finally :
740
- conn .close ()
741
738
return sms
742
739
743
740
def ShareableList (self , sequence ):
744
741
"""Returns a new ShareableList instance populated with the values
745
742
from the input sequence, to be tracked by the manager."""
746
- conn = self ._Client (self ._address , authkey = self ._authkey )
747
- try :
743
+ with self ._Client (self ._address , authkey = self ._authkey ) as conn :
748
744
sl = ShareableList (sequence )
749
745
try :
750
746
dispatch (conn , None , 'track_segment' , (sl .shm .name ,))
751
747
except BaseException as e :
752
748
sl .shm .unlink ()
753
749
raise e
754
- finally :
755
- conn .close ()
756
750
return sl
757
751
758
752
SharedMemoryManager .register ('Barrier' , threading .Barrier , BarrierProxy )
0 commit comments