Commits

sbt  committed 6f14246 Draft

Fix resource warning in test

  • Participants
  • Parent commits e8b755c
  • Branches spawn

Comments (0)

Files changed (1)

File Lib/test/test_multiprocessing.py

     def _test_closefds(cls, conn, sock_args, sock=None):
         try:
             s = socket.fromfd(*sock_args)
+            s.close()
         except Exception as e:
             conn.send(e)
         else:
     def test_closefd(self):
         if not HAS_REDUCTION:
             raise unittest.SkipTest('requires fd pickling')
-        s = self.get_high_socket()
-        reader, writer = multiprocessing.Pipe()
-        args = (writer, (s.fileno(), s.family, s.type))
-        try:
-            p = multiprocessing.Process(target=self._test_closefds, args=args)
-            p.start()
-            e = reader.recv()
-            p.join()
-        finally:
-            s.close()
-            writer.close()
-            reader.close()
+
+        with self.get_high_socket() as s:
+            reader, writer = multiprocessing.Pipe()
+            args = (writer, (s.fileno(), s.family, s.type))
+            try:
+                p = multiprocessing.Process(target=self._test_closefds,
+                                            args=args)
+                p.start()
+                e = reader.recv()
+                p.join()
+            finally:
+                s.close()
+                writer.close()
+                reader.close()
 
         if multiprocessing.get_start_method() == 'fork':
             self.assertIs(e, None)