异步工作队列
AsyncWorkQueue
实现异步队列。
源代码在 bionemo/scdl/util/async_worker_queue.py
中
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
|
__init__(max_workers=5, use_processes=False)
初始化 AsyncWorkQueue。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
max_workers
|
int
|
工作线程或进程的最大数量。 |
5
|
use_processes
|
bool
|
如果为 True,则使用 ProcessPoolExecutor;否则,使用 ThreadPoolExecutor。 |
False
|
源代码在 bionemo/scdl/util/async_worker_queue.py
中
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
|
get_completed_tasks()
获取已完成任务的列表。
返回
类型 | 描述 |
---|---|
List[Future]
|
已完成的 Future 对象列表。 |
源代码在 bionemo/scdl/util/async_worker_queue.py
中
69 70 71 72 73 74 75 76 77 |
|
get_pending_tasks()
获取待处理任务的列表。
返回
类型 | 描述 |
---|---|
List[Future]
|
尚未完成的 Future 对象列表。 |
源代码在 bionemo/scdl/util/async_worker_queue.py
中
79 80 81 82 83 84 85 86 87 |
|
get_task_results()
获取所有已完成任务的结果。
返回
类型 | 描述 |
---|---|
List[Any]
|
来自已完成任务的结果列表。 |
引发
类型 | 描述 |
---|---|
Exception
|
如果任务未能完成,或者预期会发生这种情况 |
源代码在 bionemo/scdl/util/async_worker_queue.py
中
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
|
shutdown(wait=True)
关闭执行器并等待任务完成。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
wait
|
bool
|
如果为 True,则等待所有任务完成后再关闭。 |
True
|
源代码在 bionemo/scdl/util/async_worker_queue.py
中
61 62 63 64 65 66 67 |
|
submit_task(func, *args, **kwargs)
向工作队列提交任务。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
func
|
Callable[..., Any]
|
要异步执行的函数。 |
必需 |
args
|
Any
|
传递给函数的位置参数。 |
()
|
kwargs
|
Any
|
传递给函数的关键字参数。 |
{}
|
返回
名称 | 类型 | 描述 |
---|---|---|
Future |
Future
|
异步操作的占位符。 |
源代码在 bionemo/scdl/util/async_worker_queue.py
中
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
|
wait()
等待所有提交的任务完成并返回其结果。
返回
类型 | 描述 |
---|---|
List[Any]
|
来自所有已完成任务的结果列表。 |
源代码在 bionemo/scdl/util/async_worker_queue.py
中
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
|