Python 使用IoT边缘中的OPCUa订阅导出数据

Python 使用IoT边缘中的OPCUa订阅导出数据,python,async-await,opc-ua,azure-iot-edge,Python,Async Await,Opc Ua,Azure Iot Edge,我试图作为OPCUA客户端接收数据,因此我为一些数据节点创建了订阅。接收数据没有问题,但将其导出为IoT客户端才是问题所在。我想我必须并行运行两个线程。使用以下代码: class Publisher(): def __init__(self): self.module_client = IoTHubModuleClient.create_from_edge_environment() async def export_data(self, message, o

我试图作为OPCUA客户端接收数据,因此我为一些数据节点创建了订阅。接收数据没有问题,但将其导出为IoT客户端才是问题所在。我想我必须并行运行两个线程。使用以下代码:

class Publisher():
    def __init__(self):
        self.module_client = IoTHubModuleClient.create_from_edge_environment()


    async def export_data(self, message, output):
        """Serializes databuffer to json string"""
        print('Export')
        self.module_client.send_message_to_output(message, output)
        print('Exported completed')


class Handler(object):
    """
    Client to subscription. It will receive events from server
    """
    def __init__(self):
        """"""
        self.publisher = Publisher()


    def datachange_notification(self, node, val, data):
        self.publisher.export_data('test', 'output1')


url = "opc.tcp://192.168.3.5:4840"
opcua_client = Client(url)
opcua_client.connect()
opcua_broker = Handler()

sub = opcua_client.create_subscription(20, opcua_broker)
node_list = [opcua_client.get_node('ns=3;s="EM126_Log"."DataLogL"[1]')]
handler = sub.subscribe_data_change(node_list)

time.sleep(100)
错误如下: “运行时警告:从未等待协同程序‘Publisher.export_data’”


是否有人知道如何导出de Handler类中的传入数据(数据更改通知)

async def export\u data
您在这里定义了一个协同程序。这需要
wait
ed。协同路由用于异步代码中,因此它们可以并行运行。提供一个简单的例子。缺少您的导入语句。同时执行
pip冻结
,并提供您正在使用的opcua库的信息。您应该避免在异步代码中使用
time.sleep()
。它会中止你的整个计划。如果opcua库支持asyncio,则您将不需要并行线程。您好,使用这些导入:从azure.iot.device.aio导入IoTubModuleClient from datetime导入datetime、timezone、timedelta from opcua导入客户端导入asyncio导入timeI也尝试在datachange_通知中添加导出,但这不起作用。这就是我尝试使用两个独立线程的原因。