python-sdk icon indicating copy to clipboard operation
python-sdk copied to clipboard

HTTP Service invocation: Add native synchronous execution

Open igorya7v opened this issue 2 years ago • 3 comments

When the loop is already running, the following line will raise the RuntimeError: This event loop is already running:
https://github.com/dapr/python-sdk/blob/033acbc92b4c4b40577c603aa5b03694eb74e295/dapr/clients/http/dapr_invocation_http_client.py#L161

This happens when the following line returns an already running loop:
https://github.com/dapr/python-sdk/blob/033acbc92b4c4b40577c603aa5b03694eb74e295/dapr/clients/http/dapr_invocation_http_client.py#L147

igorya7v avatar May 12 '23 03:05 igorya7v

This is too much work to fix for the upcoming release. Clearly calling the asynchronous implementation from a synchronous context isn't working for every situation.

Can you please call async def invoke_method_async instead?

berndverst avatar May 31 '23 23:05 berndverst

We basically need synchronous method implementation of DaprHttpClient and then use that in the invoke_method implementation in DaprInvocationHttpClient. And we need additional tests for this.

berndverst avatar May 31 '23 23:05 berndverst

For the time being, please use the example shown here which uses Python requests directly for a basic service invocation call. As long as you set the dapr-app-id header and specify the sidecar address as destination, any path will be routed to the target app and invoked accordingly. There is no need to use the Python SDK.

https://github.com/dapr/quickstarts/blob/master/service_invocation/python/http/checkout/app.py

berndverst avatar Aug 17 '23 23:08 berndverst