码迷,mamicode.com
首页 > 编程语言 > 详细

很简单的多线程访问python嘿嘿嘿

时间:2016-05-01 16:02:21      阅读:247      评论:0      收藏:0      [点我收藏+]

标签:

import urllib
import socket
from threading import *
 
url = "http://www.baidu.com/s?ie=UTF-8&wd=tofind.space"
cishu = 0
socket.setdefaulttimeout(15)
 
 
def gethtml():
    global cishu
    cishu += 1
    print cishu
    urllib.urlopen(url).read()
 
 
def attack():
    while True:
        try:
            gethtml()
        except error:
            pass
 
 
def run():
    t = Thread(target=attack)
    t.start()
 
for i in range(10):
    run()

 

很简单的多线程访问python嘿嘿嘿

标签:

原文地址:http://www.cnblogs.com/learn-to-rock/p/5450504.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!