Python 如何在运行其他代码时运行异步websocket?

Python 如何在运行其他代码时运行异步websocket?,python,asynchronous,websocket,Python,Asynchronous,Websocket,我有以下代码: async def echo(websocket, path): async for message in websocket: await websocket.send(message) asyncio.get_event_loop().run_until_complete( websockets.serve(echo, 'localhost', 8765)) asyncio.get_event_loop().run_forever() 但是

我有以下代码:

async def echo(websocket, path):
    async for message in websocket:
        await websocket.send(message)

asyncio.get_event_loop().run_until_complete(
    websockets.serve(echo, 'localhost', 8765))
asyncio.get_event_loop().run_forever()

但是我想在.run_forever()方法之后运行其他代码,但是该方法会使代码挂起。在此之后,我如何继续执行代码?谢谢大家!

可能对你有帮助。@Yeheshuah这些例子都没有使用async或Wait。我不确定这对我有什么帮助?可能对你有帮助。@Yeheshuah这些例子都没有使用async或Wait。我不确定这对我有什么帮助?