写点什么

《Operating System Concepts》阅读笔记:p179-p179

作者:codists
  • 2025-03-03
    广东
  • 本文字数:838 字

    阅读完需:约 3 分钟

《Operating System Concepts》学习第 19 天,p179-p179 总结,总计 1 页。

一、技术总结

1.Python thread pool

(1)示例


书上介绍的是 Java thread poo, 因为本人工作中使用的编程语言是 Python, 所以补充一下 Python 中的 thread pool 用例。


import concurrent.futuresimport urllib.request
URLS = ['http://www.foxnews.com/', 'http://www.cnn.com/', 'http://europe.wsj.com/', 'http://www.bbc.co.uk/', 'http://nonexistent-subdomain.python.org/']

# Retrieve a single page and report the URL and contentsdef load_url(url, timeout): with urllib.request.urlopen(url, timeout=timeout) as conn: return conn.read()

# We can use a with statement to ensure threads are cleaned up promptlywith concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor: # Start the load operations and mark each future with its URL future_to_url = {executor.submit(load_url, url, 60): url for url in URLS} for future in concurrent.futures.as_completed(future_to_url): url = future_to_url[future] try: data = future.result() except Exception as exc: print('%r generated an exception: %s' % (url, exc)) else: print('%r page is %d bytes' % (url, len(data)))
复制代码

二、英语总结(生词:0)

无。


关于英语的注解同步更新汇总到 https://github.com/codists/English-In-CS-Books 仓库。

三、其它

今天没有什么想说的。

四、参考资料

1. 编程

(1) Abraham Silberschatz,Peter Baer Galvin,Greg Gagne《Operating System Concepts》:https://book.douban.com/subject/30272539/

2. 英语

(1) Etymology Dictionary:https://www.etymonline.com


(2) Cambridge Dictionary:https://dictionary.cambridge.org


欢迎搜索及关注:编程人(a_codists)


发布于: 刚刚阅读数: 3
用户头像

codists

关注

公众号:编程人 2021-01-14 加入

Life is short, You need Python

评论

发布
暂无评论
《Operating System Concepts》阅读笔记:p179-p179_操作系统_codists_InfoQ写作社区