【发布时间】:2021-02-04 16:00:59
【问题描述】:
我有 C 编程经验和 Python 新手。我想连续运行 fucntion1 和 fucntion2 而不是等待服务器关闭。现在下面的代码运行一次函数并等待服务器。如何运行函数?请帮忙
async def main():
function1()
function2()
server = await websockets.serve(
on_connect,
'192.168.1.251',
9000,
subprotocols=['ocpp1.6'],
ping_interval = 10,
ping_timeout = 120
)
logging.info("Server Started listening to new connections...")
await server.wait_closed()
【问题讨论】:
-
感谢您的快速回复。我会在这里验证和更新
-
我添加了代码并启动了线程,但它只运行了一次。我正在打印一些在输出中只能看到一次的文本。
-
在
asyncio你可以运行多个任务。 docs.python.org/3/library/… -
我想重复运行这些函数。我尝试使用 await 和 async 进行更改,但我仍然只能看到一次输出,并且套接字服务器正在运行直到它关闭。
标签: python async-await