程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了将异步函数作为同步 lambda 传递 史前史问题:RuntimeWarning: coroutine 'RuntimeWarning: coroutine '...' was never awaited。代码附注所有代码都在 asyncio 循环中运行。大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决将异步函数作为同步 lambda 传递 史前史问题:RuntimeWarning: coroutIne 'RuntimeWarning: coroutIne '...' was never awaited。代码附注所有代码都在 asyncio 循环中运行。?

开发过程中遇到将异步函数作为同步 lambda 传递 史前史问题:RuntimeWarning: coroutIne 'RuntimeWarning: coroutIne '...' was never awaited。代码附注所有代码都在 asyncio 循环中运行。的问题如何解决?下面主要结合日常开发的经验,给出你关于将异步函数作为同步 lambda 传递 史前史问题:RuntimeWarning: coroutIne 'RuntimeWarning: coroutIne '...' was never awaited。代码附注所有代码都在 asyncio 循环中运行。的解决方法建议,希望对你解决将异步函数作为同步 lambda 传递 史前史问题:RuntimeWarning: coroutIne 'RuntimeWarning: coroutIne '...' was never awaited。代码附注所有代码都在 asyncio 循环中运行。有所启发或帮助;

史前史

你好!想要使用 2 个包 (websockets + signalrcore)。一个 websockets 想要 await connection.send()... 使包装函数异步。但是 signalrcore on() 方法接受同步 lamda。

问题:RuntimeWarning: coroutIne 'RuntimeWarning: coroutIne '...' was never awaited

我可以问一些解决这个问题的想法吗?

代码

 def connectToSignalR(self,uri: str):
        ...
        self.hub_connection.on_open(lambda: print("connection opened and handshake received ready to send messages"))
        self.hub_connection.on_close(lambda: print("connection closed"))
        self.hub_connection.on("ReceiveDirectmessage",lambda x: self.onReceiveDirectmessage(X)) # HERE
        self.hub_connection.start()

    async def onReceiveDirectmessage(self,message: str) -> None:
        logging.info(messagE)
        await self.wsCon.send("abcdef")

附注所有代码都在 asyncio 循环中运行。

if __name__ == '__main__':
    server = Server()
    start_server = websockets.serve(server.ws_handler,host,port)
    loop = asyncio.get_event_loop()
    loop.run_until_complete(start_server)
    loop.run_forever()

p.p.s.我正在尝试实现简单的连接器 user -> websocket -> signalr -> websocket -> user 因为目标应用程序不能使用 signalr 进行连接。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

大佬总结

以上是大佬教程为你收集整理的将异步函数作为同步 lambda 传递 史前史问题:RuntimeWarning: coroutine 'RuntimeWarning: coroutine '...' was never awaited。代码附注所有代码都在 asyncio 循环中运行。全部内容,希望文章能够帮你解决将异步函数作为同步 lambda 传递 史前史问题:RuntimeWarning: coroutine 'RuntimeWarning: coroutine '...' was never awaited。代码附注所有代码都在 asyncio 循环中运行。所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。