Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Websocket客户端上的Python线程池_Python_Multithreading_Threadpool - Fatal编程技术网

Websocket客户端上的Python线程池

Websocket客户端上的Python线程池,python,multithreading,threadpool,Python,Multithreading,Threadpool,我有一个web套接字客户端,它使用asyncio从websocket服务器接收消息 async def web_socket(server): async with websockets.connect(server) as websocket: message = await websocket.recv() t = Thread(target=message_helper.process_message,args(message)) t.start() 来自webs

我有一个web套接字客户端,它使用asyncio从websocket服务器接收消息

async def web_socket(server):
async with websockets.connect(server) as websocket:
    message = await websocket.recv()
    t = Thread(target=message_helper.process_message,args(message))
    t.start()
来自websocket服务器的消息传入得非常快,并且无限期运行。我想设置一个线程池,以确保我有足够的线程

我看到的所有示例都设置了一个队列(这里有一个示例:。我看到的所有示例都有一个预定义的任务数组,然后它开始使用线程池处理它们

在我上面的示例中,我不知道如何实现这一点?因为消息每秒都会传入,我想启动一个线程来处理传入的每个消息。当我没有预定义的任务数组时,有没有办法实现我试图用线程池做的事?

可以吗


谢谢,这就是我要找的,我只是定义了executor,而不是像您那样使用任何executor.executor=concurrent.futures.ThreadPoolExecutor(max\u-workers=30)
async def web_socket(server):
    async with websockets.connect(server) as websocket:
        message = await websocket.recv()
        loop.run_in_executor(None, message_helper.process_message, args(message))