summaryrefslogtreecommitdiffstats
path: root/bitbake/bin
diff options
context:
space:
mode:
authorJoshua Watt <JPEWhacker@gmail.com>2023-11-03 08:26:21 -0600
committerRichard Purdie <richard.purdie@linuxfoundation.org>2023-11-09 17:33:02 +0000
commit732ff20cf9d438537129612124a82b7789881c97 (patch)
tree157dfc1450df3f29e0d90fcdeeb16614d9cdf957 /bitbake/bin
parent2484bd893189bc24ac210edf2de3b7e1115eebd3 (diff)
downloadpoky-732ff20cf9d438537129612124a82b7789881c97.tar.gz
bitbake: asyncrpc: Add context manager API
Adds context manager API for the asyncrcp client class which allow writing code that will automatically close the connection like so: with hashserv.create_client(address) as client: ... Rework the bitbake-hashclient tool and PR server to use this new API to fix warnings about unclosed event loops when exiting (Bitbake rev: d01d684a0f6398270fe35ed59b7d28f3fd9b7e41) Signed-off-by: Joshua Watt <JPEWhacker@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/bin')
-rwxr-xr-xbitbake/bin/bitbake-hashclient36
1 files changed, 17 insertions, 19 deletions
diff --git a/bitbake/bin/bitbake-hashclient b/bitbake/bin/bitbake-hashclient
index 3f265e8fa7..a02a65b937 100755
--- a/bitbake/bin/bitbake-hashclient
+++ b/bitbake/bin/bitbake-hashclient
@@ -56,25 +56,24 @@ def main():
56 nonlocal missed_hashes 56 nonlocal missed_hashes
57 nonlocal max_time 57 nonlocal max_time
58 58
59 client = hashserv.create_client(args.address) 59 with hashserv.create_client(args.address) as client:
60 60 for i in range(args.requests):
61 for i in range(args.requests): 61 taskhash = hashlib.sha256()
62 taskhash = hashlib.sha256() 62 taskhash.update(args.taskhash_seed.encode('utf-8'))
63 taskhash.update(args.taskhash_seed.encode('utf-8')) 63 taskhash.update(str(i).encode('utf-8'))
64 taskhash.update(str(i).encode('utf-8'))
65 64
66 start_time = time.perf_counter() 65 start_time = time.perf_counter()
67 l = client.get_unihash(METHOD, taskhash.hexdigest()) 66 l = client.get_unihash(METHOD, taskhash.hexdigest())
68 elapsed = time.perf_counter() - start_time 67 elapsed = time.perf_counter() - start_time
69 68
70 with lock: 69 with lock:
71 if l: 70 if l:
72 found_hashes += 1 71 found_hashes += 1
73 else: 72 else:
74 missed_hashes += 1 73 missed_hashes += 1
75 74
76 max_time = max(elapsed, max_time) 75 max_time = max(elapsed, max_time)
77 pbar.update() 76 pbar.update()
78 77
79 max_time = 0 78 max_time = 0
80 found_hashes = 0 79 found_hashes = 0
@@ -174,9 +173,8 @@ def main():
174 173
175 func = getattr(args, 'func', None) 174 func = getattr(args, 'func', None)
176 if func: 175 if func:
177 client = hashserv.create_client(args.address) 176 with hashserv.create_client(args.address) as client:
178 177 return func(args, client)
179 return func(args, client)
180 178
181 return 0 179 return 0
182 180