使用线程队列

w

使用 Python 进行线程编程
https://www.ibm.com/developerworks/cn/aix/library/au-threadingpython/index.html

C:>python E:MATHpyCLIurl_fetch_serial.py
<!DOCTYPE html>
<html>
  <head>
    <meta charset='utf-8'>
    <title>Redis</title>
    <link href='/styles.css' rel='stylesheet'>
    <link href='/images/favicon.png' rel='shortcut icon'>
    <link href='/opensearch.xml' rel='search' title='Look up a Redis command' type='application/opensearchdescri
    <meta content='width=device-width, minimum-scale=1.0, maximum-scale=1.0' name='viewport'>
    <script>
       var _gaq = _gaq || [];
       _gaq.push(['_setAccount', 'UA-20243082-1']);
       _gaq.push(['_trackPageview']);

       (function() {
         var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
         ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.c
         var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
       })();
    </script>
  </head>
  <body class=''>
    <div class='mobile-menu slideout-menu'>
      <header class='menu-header'></heade
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link rel="icon" type="image/x-icon" href="/favicon.ico" />
    <link type="text/css" href="/css/pages.css" media="all" rel="stylesheet">

    <!-- Begin Jekyll SEO tag v2.2.0 -->
<title>GitHub Pages | Websites for you and your projects, hosted directly from your GitHub repository. Just edit
<meta property="og:title" content="GitHub Pages" />
<meta property="og:locale" content="en_US" />
<meta name="description" content="Websites for you and your projects, hosted directly from your GitHub repositor
<meta property="og:description" content="Websites for you and your projects, hosted directly from your GitHub re
<link rel="canonical" href="https://pages.github.com/" />
<meta property="og:url" content="https://pages.github.com/" />
<meta property="og
Elapsed Time: 20.3339998722

C:>

url_fetch_serial.py

import urllib2
import time
#hosts = ["https://apple.com","https://ibm.com","https://amazon.com"]
hosts = ["https://redis.io","http://github.io"]

start = time.time()

for host in hosts:
    url = urllib2.urlopen(host)
    print url.read(1024)
print "Elapsed Time: %s" % (time.time()-start)
原文地址:https://www.cnblogs.com/rsapaper/p/6785499.html