Tornado 6.5 Documentation
item. A Queue maintains a count of unfinished tasks, which begins at zero. put increments the count; task_done decrements it. In the web-spider example here, the queue begins containing only base_url. When calls task_done to decrement the counter once. Eventually, a worker fetches a page whose URLs have all been seen before, and there is also no work left in the queue. Thus that worker’s call to task_done print(f"Exception: {e} {url}") dead.add(url) finally: q.task_done() await q.put(base_url) # Start workers, then wait for the work queue to be empty.0 码力 | 437 页 | 405.14 KB | 2 月前3Tornado 6.5 Documentation
item. A Queue maintains a count of unfinished tasks, which begins at zero. put increments the count; task_done decrements it. In the web-spider example here, the queue begins containing only base_url. When calls task_done to decrement the counter once. Eventually, a worker fetches a page whose URLs have all been seen before, and there is also no work left in the queue. Thus that worker’s call to task_done await fetch_url(url) except Exception as e: print(f"Exception: {e} {url}") dead.add(url) finally: q.task_done() await q.put(base_url) # Start workers, then wait for the work queue to be empty. workers0 码力 | 272 页 | 1.12 MB | 2 月前3Rust 程序设计语言 简体中文版 1.85.0
是单独一个人,所以无法真正同时推进两个任务,但是你可以多任务处理,在不同任务之间切 换以取得进展。 Task A Task B A1 A2 B1 A3 B2 A4 B3 当你同意将一组任务在组员中分配,每一个组员分配一个任务并单独处理它,这就是 并行。 每个组员可以真正同时进行工作。 Task B Task A B1 B2 B3 A1 A2 A3 A4 在这两种场景中,你可能需要协调不同的任务。也许你 一位成员的工作完成。一些工作可以并行进 行,不过一些工作事实上是 串行 的:它们只能串行地发生,一个接着一个,如图 17-3 所示。 376/562Rust 程序设计语言 简体中文版 Task A Task B A1 A2 A3 B1 B2 B3 B4 同理,你可能会意识到你自己的一个任务依赖另一个任务。现在并发任务也变成串行的了。 并行与并发也可能相互交叉(阻塞)。如果你得知某个同事卡在等待你的一个任务完成,你可 异步编程的关键元素是 futures 和 Rust 的 async 与 await 关键字。 future 是一个现在可能还没有准备好但将在未来某个时刻准备好的值。(相同的概念也出现在 很多语言中,有时被称为 “task” 或者 “promise”。)Rust 提供了 Future trait 作为基础组件, 这样不同的异步操作就可以在不同的数据结构上实现。在 Rust 中,我们称实现了 Future trait0 码力 | 562 页 | 3.23 MB | 9 天前3
共 3 条
- 1