mirror of
https://github.com/python/cpython.git
synced 2025-12-09 10:37:17 +00:00
Avoid ResourceWarnings in ccbench
This commit is contained in:
parent
6a002c02da
commit
126c8b4a82
1 changed files with 13 additions and 12 deletions
|
|
@ -276,19 +276,19 @@ def _recv(sock, n):
|
||||||
return sock.recv(n).decode('ascii')
|
return sock.recv(n).decode('ascii')
|
||||||
|
|
||||||
def latency_client(addr, nb_pings, interval):
|
def latency_client(addr, nb_pings, interval):
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock:
|
||||||
_time = time.time
|
_time = time.time
|
||||||
_sleep = time.sleep
|
_sleep = time.sleep
|
||||||
def _ping():
|
def _ping():
|
||||||
_sendto(sock, "%r\n" % _time(), addr)
|
_sendto(sock, "%r\n" % _time(), addr)
|
||||||
# The first ping signals the parent process that we are ready.
|
# The first ping signals the parent process that we are ready.
|
||||||
_ping()
|
|
||||||
# We give the parent a bit of time to notice.
|
|
||||||
_sleep(1.0)
|
|
||||||
for i in range(nb_pings):
|
|
||||||
_sleep(interval)
|
|
||||||
_ping()
|
_ping()
|
||||||
_sendto(sock, LAT_END + "\n", addr)
|
# We give the parent a bit of time to notice.
|
||||||
|
_sleep(1.0)
|
||||||
|
for i in range(nb_pings):
|
||||||
|
_sleep(interval)
|
||||||
|
_ping()
|
||||||
|
_sendto(sock, LAT_END + "\n", addr)
|
||||||
|
|
||||||
def run_latency_client(**kwargs):
|
def run_latency_client(**kwargs):
|
||||||
cmd_line = [sys.executable, '-E', os.path.abspath(__file__)]
|
cmd_line = [sys.executable, '-E', os.path.abspath(__file__)]
|
||||||
|
|
@ -363,6 +363,7 @@ def run_latency_test(func, args, nthreads):
|
||||||
for t in threads:
|
for t in threads:
|
||||||
t.join()
|
t.join()
|
||||||
process.wait()
|
process.wait()
|
||||||
|
sock.close()
|
||||||
|
|
||||||
for recv_time, chunk in chunks:
|
for recv_time, chunk in chunks:
|
||||||
# NOTE: it is assumed that a line sent by a client wasn't received
|
# NOTE: it is assumed that a line sent by a client wasn't received
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue