summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb
diff options
context:
space:
mode:
authorJoshua Watt <JPEWhacker@gmail.com>2023-11-03 08:26:21 -0600
committerSteve Sakoman <steve@sakoman.com>2024-01-10 05:14:16 -1000
commit6c7c9b11465a0f35cbae907b8b9d5374f8130587 (patch)
treeb979013dcce97f7534aadd8f923cbe24dcaaa5d6 /bitbake/lib/bb
parent3ef22a75a3d97cd68ebaad476882937baedd9d25 (diff)
downloadpoky-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/lib/bb')
-rw-r--r--bitbake/lib/bb/asyncrpc/client.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/bitbake/lib/bb/asyncrpc/client.py b/bitbake/lib/bb/asyncrpc/client.py
index fa042bbe87..dcbe7e5762 100644
--- a/bitbake/lib/bb/asyncrpc/client.py
+++ b/bitbake/lib/bb/asyncrpc/client.py
@@ -126,6 +126,12 @@ class AsyncClient(object):
126 {'ping': {}} 126 {'ping': {}}
127 ) 127 )
128 128
129 async def __aenter__(self):
130 return self
131
132 async def __aexit__(self, exc_type, exc_value, traceback):
133 await self.close()
134
129 135
130class Client(object): 136class Client(object):
131 def __init__(self): 137 def __init__(self):
@@ -176,3 +182,10 @@ class Client(object):
176 if sys.version_info >= (3, 6): 182 if sys.version_info >= (3, 6):
177 self.loop.run_until_complete(self.loop.shutdown_asyncgens()) 183 self.loop.run_until_complete(self.loop.shutdown_asyncgens())
178 self.loop.close() 184 self.loop.close()
185
186 def __enter__(self):
187 return self
188
189 def __exit__(self, exc_type, exc_value, traceback):
190 self.close()
191 return False