Port RPC "registry.call_client" to async

This commit is contained in:
Ivan Kravets
2023-01-27 20:53:43 +02:00
parent 464b167e65
commit 0d57a799b5

View File

@ -13,16 +13,17 @@
# limitations under the License. # limitations under the License.
from ajsonrpc.core import JSONRPC20DispatchException from ajsonrpc.core import JSONRPC20DispatchException
from starlette.concurrency import run_in_threadpool
from platformio.registry.client import RegistryClient from platformio.registry.client import RegistryClient
class RegistryRPC: class RegistryRPC:
@staticmethod @staticmethod
def call_client(method, *args, **kwargs): async def call_client(method, *args, **kwargs):
try: try:
client = RegistryClient() client = RegistryClient()
return getattr(client, method)(*args, **kwargs) return await run_in_threadpool(getattr(client, method), *args, **kwargs)
except Exception as exc: # pylint: disable=bare-except except Exception as exc: # pylint: disable=bare-except
raise JSONRPC20DispatchException( raise JSONRPC20DispatchException(
code=5000, message="Registry Call Error", data=str(exc) code=5000, message="Registry Call Error", data=str(exc)