mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-31 10:37:13 +02:00
Port RPC "registry.call_client" to async
This commit is contained in:
@ -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)
|
||||||
|
Reference in New Issue
Block a user