小编abr*_*uez的帖子

Python 模块“asyncio”没有属性“to_thread”

来自 python 的 asyncio 示例:

import asyncio
import time
def blocking_io():
    print(f"start blocking_io at {time.strftime('%X')}")
    # Note that time.sleep() can be replaced with any blocking
    # IO-bound operation, such as file operations.
    time.sleep(1)
    print(f"blocking_io complete at {time.strftime('%X')}")

async def main():
    print(f"started main at {time.strftime('%X')}")

    await asyncio.gather(
        asyncio.to_thread(blocking_io),
        asyncio.sleep(1))

    print(f"finished main at {time.strftime('%X')}")


asyncio.run(main())

# Expected output:
#
# started main at 19:50:53
# start blocking_io at 19:50:53
# blocking_io complete at 19:50:54
# finished main at 19:50:54
Run Code Online (Sandbox Code Playgroud)

它正在输出下一个错误:

    asyncio.to_thread(blocking_io),
    AttributeError: …
Run Code Online (Sandbox Code Playgroud)

python concurrency multithreading python-asyncio

9
推荐指数
1
解决办法
9635
查看次数

串行控制台通信如何在微控制器中工作?

我的疑问是关于通信的物理层,我从实践中知道,例如使用 teraterm 与 MCU 通信只是启用和配置 UART 外设,然后通过 USB 连接微控制器和瞧。

但对我来说,如果 USB 连接到 DN 和 DP,而 UART 使用 RX 和 TX,主机如何有效地与微控制器通信,这对我来说还没有意义?

c embedded microcontroller arm uart

0
推荐指数
1
解决办法
380
查看次数