首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

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

《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. 英语

  • 发表于:
  • 原文链接https://page.om.qq.com/page/O6jwYUwyjNyCtmf9QJqWRT1w0
  • 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 cloudcommunity@tencent.com 删除。

扫码

添加站长 进交流群

领取专属 10元无门槛券

私享最新 技术干货

扫码加入开发者社群
领券