summaryrefslogtreecommitdiffstats
path: root/Tools
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-01-15 11:39:23 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2011-01-15 11:39:23 (GMT)
commit126c8b4a82fdac14c722f11ed4e0a33dcefa4f6b (patch)
treee74efe0972e4e4d8f3962bac97378424da7b8cc6 /Tools
parent6a002c02dad9e33847f6f123be499c998e40cccf (diff)
downloadcpython-126c8b4a82fdac14c722f11ed4e0a33dcefa4f6b.zip
cpython-126c8b4a82fdac14c722f11ed4e0a33dcefa4f6b.tar.gz
cpython-126c8b4a82fdac14c722f11ed4e0a33dcefa4f6b.tar.bz2
Avoid ResourceWarnings in ccbench
Diffstat (limited to 'Tools')
-rw-r--r--Tools/ccbench/ccbench.py25
1 files changed, 13 insertions, 12 deletions
diff --git a/Tools/ccbench/ccbench.py b/Tools/ccbench/ccbench.py
index 569ec21..02b192f 100644
--- a/Tools/ccbench/ccbench.py
+++ b/Tools/ccbench/ccbench.py
@@ -276,19 +276,19 @@ def _recv(sock, n):
return sock.recv(n).decode('ascii')
def latency_client(addr, nb_pings, interval):
- sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
- _time = time.time
- _sleep = time.sleep
- def _ping():
- _sendto(sock, "%r\n" % _time(), addr)
- # 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)
+ with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock:
+ _time = time.time
+ _sleep = time.sleep
+ def _ping():
+ _sendto(sock, "%r\n" % _time(), addr)
+ # The first ping signals the parent process that we are ready.
_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):
cmd_line = [sys.executable, '-E', os.path.abspath(__file__)]
@@ -363,6 +363,7 @@ def run_latency_test(func, args, nthreads):
for t in threads:
t.join()
process.wait()
+ sock.close()
for recv_time, chunk in chunks:
# NOTE: it is assumed that a line sent by a client wasn't received