Mercurial > hg
comparison tests/run-tests.py @ 45955:064449f9fdc2
run-tests: use a context manager when looking for available ports
Differential Revision: https://phab.mercurial-scm.org/D9441
Differential Revision: https://phab.mercurial-scm.org/D9452
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Sun, 29 Nov 2020 19:17:35 +0530 |
parents | 89a2afe31e82 |
children | f44b9c72f061 |
comparison
equal
deleted
inserted
replaced
45954:a120d1c9c704 | 45955:064449f9fdc2 |
---|---|
45 | 45 |
46 from __future__ import absolute_import, print_function | 46 from __future__ import absolute_import, print_function |
47 | 47 |
48 import argparse | 48 import argparse |
49 import collections | 49 import collections |
50 import contextlib | |
50 import difflib | 51 import difflib |
51 import distutils.version as version | 52 import distutils.version as version |
52 import errno | 53 import errno |
53 import json | 54 import json |
54 import multiprocessing | 55 import multiprocessing |
253 if useipv6: | 254 if useipv6: |
254 family = socket.AF_INET6 | 255 family = socket.AF_INET6 |
255 else: | 256 else: |
256 family = socket.AF_INET | 257 family = socket.AF_INET |
257 try: | 258 try: |
258 s = socket.socket(family, socket.SOCK_STREAM) | 259 with contextlib.closing(socket.socket(family, socket.SOCK_STREAM)) as s: |
259 s.bind(('localhost', port)) | 260 s.bind(('localhost', port)) |
260 s.close() | |
261 return True | 261 return True |
262 except socket.error as exc: | 262 except socket.error as exc: |
263 if exc.errno not in ( | 263 if exc.errno not in ( |
264 errno.EADDRINUSE, | 264 errno.EADDRINUSE, |
265 errno.EADDRNOTAVAIL, | 265 errno.EADDRNOTAVAIL, |