dapr / python-sdk

Dapr SDK for Python
Apache License 2.0
222 stars 125 forks source link

HTTP Service invocation: Add native synchronous execution #564

Open igorya7v opened 1 year ago

igorya7v commented 1 year ago

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

berndverst commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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