Skip to main content
 首页 » 编程设计

python之Gevent 等待作业完成(joinall vs wait)

2025年05月04日10emanlee

第一个文档的 example等待所有生成的作业完成:

gevent.joinall(jobs, timeout=2) 

然而,joinall没有记录但wait方法是:

Wait for objects to become ready or for event loop to finish.

这两种方法是否具有相同的功能,只是在实现上有所不同?

请您参考如下方法:

joinall 记录在案:

joinall(greenlets, timeout=None, raise_error=False, count=None) Wait for the greenlets to finish.

Parameters:
greenlets – A sequence (supporting len()) of greenlets to wait for. timeout (float) – If given, the maximum number of seconds to wait. Returns: A sequence of the greenlets that finished before the timeout (if any) expired.

如您所见,它们在功能上存在差异。最大的一个是 wait 适用于很多事情,而 joinall 只适用于 greenlets。所以 joinall 的功能是为 greenlets 定制的。