Skip to content

Commit 0be0531

Browse files
committed
Missed opportunity to use with statement.
1 parent 1076567 commit 0be0531

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

Lib/multiprocessing/shared_memory.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -728,31 +728,25 @@ def get_server(self):
728728
def SharedMemory(self, size):
729729
"""Returns a new SharedMemory instance with the specified size in
730730
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:
733732
sms = SharedMemory(None, flags=O_CREX, size=size)
734733
try:
735734
dispatch(conn, None, 'track_segment', (sms.name,))
736735
except BaseException as e:
737736
sms.unlink()
738737
raise e
739-
finally:
740-
conn.close()
741738
return sms
742739

743740
def ShareableList(self, sequence):
744741
"""Returns a new ShareableList instance populated with the values
745742
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:
748744
sl = ShareableList(sequence)
749745
try:
750746
dispatch(conn, None, 'track_segment', (sl.shm.name,))
751747
except BaseException as e:
752748
sl.shm.unlink()
753749
raise e
754-
finally:
755-
conn.close()
756750
return sl
757751

758752
SharedMemoryManager.register('Barrier', threading.Barrier, BarrierProxy)

0 commit comments

Comments
 (0)