diff options
| author | Joshua Watt <JPEWhacker@gmail.com> | 2023-11-03 08:26:21 -0600 |
|---|---|---|
| committer | Steve Sakoman <steve@sakoman.com> | 2024-01-10 05:14:16 -1000 |
| commit | 6c7c9b11465a0f35cbae907b8b9d5374f8130587 (patch) | |
| tree | b979013dcce97f7534aadd8f923cbe24dcaaa5d6 /bitbake/bin | |
| parent | 3ef22a75a3d97cd68ebaad476882937baedd9d25 (diff) | |
| download | poky-6c7c9b11465a0f35cbae907b8b9d5374f8130587.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: ee090484cc25d760b8c20f18add17b5eff485b40)
Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
(cherry picked from commit d01d684a0f6398270fe35ed59b7d28f3fd9b7e41)
Signed-off-by: Steve Sakoman <steve@sakoman.com>
Diffstat (limited to 'bitbake/bin')
| -rwxr-xr-x | bitbake/bin/bitbake-hashclient | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/bitbake/bin/bitbake-hashclient b/bitbake/bin/bitbake-hashclient index 494f17592a..7c57866d36 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 |
| @@ -152,9 +151,8 @@ def main(): | |||
| 152 | 151 | ||
| 153 | func = getattr(args, 'func', None) | 152 | func = getattr(args, 'func', None) |
| 154 | if func: | 153 | if func: |
| 155 | client = hashserv.create_client(args.address) | 154 | with hashserv.create_client(args.address) as client: |
| 156 | 155 | return func(args, client) | |
| 157 | return func(args, client) | ||
| 158 | 156 | ||
| 159 | return 0 | 157 | return 0 |
| 160 | 158 | ||
