Skip to content

Using coroutines as iothub_client callbacks #96

@DanielDiBe

Description

@DanielDiBe

OS: Debian GNU/Linux 9.2 (stretch)
Python: 3.5.3
SDK client: '1.1.19.0'

Description of the issue:

The SDK iothub_client does not accept setting a coroutine as a callback for set_device_method_callback.

Anything that gives me the ability to execute asynchronous code with the iot_hub client callbacks instead of forcing the device to return synchronously a value would work for me. For example the callback could have a callback function itself, or a Future, I could use to return the value instead of returning it via the return statement.

Code sample exhibiting the issue:

import iothub_client
import asyncio

client = iothub_client.IoTHubClient("{connection string}", iothub_client.IoTHubTransportProvider.MQTT_WS)
client.set_device_method_callback(device_method_callback, 0)
async def device_method_callback(method_name, payload, user_context):
    print("Direct method:", method_name)
    return await asyncio.sleep(3, result=10)

Console log of the issue:

When calling a direct method to the device, the device code produces the following output because the call to the provided function creates a coroutine. The SDK does not try to execute the coroutine and undestands it as the result of the callback instead, which causes an error:
TypeError: No registered converter was able to produce a C++ rvalue of type DeviceMethodReturnValue from this Python object of type coroutine

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions