这是一个创建于 3938 天前的主题,其中的信息可能已经有所发展或是发生改变。
代码如下,初学python,如有不正确的地方请大神指正
#coding=utf-8
import requests
import threading
import time
import Queue
geturl='http://192.168.1.41/login.php'#内部服务器地址,可以改成自己的
xrange_num=1000#设置循环总次数
con_num=20#设置线程数
start=time.time()
class testThread(threading.Thread):
def __init__(self,queue):
threading.Thread.__init__(self)
self.queue = queue
def run(self):
while 1:
try:
url= self.queue.get_nowait()
except Queue.Empty:
raise SystemExit
requests.get(url)
queue = Queue.Queue()
for x in xrange(xrange_num):
#line = line.strip()
queue.put(geturl)
threads = []
for dummy in xrange(con_num):
t = testThread(queue)
t.start()
threads.append(t)
# Wait for all threads to finish
for thread in threads:
thread.join()
print time.time()-start
import gevent
from gevent import monkey
monkey.patch_all()
from gevent.pool import Pool
import requests
start2=time.time()
p = Pool(con_num)
def down(url):
requests.get(url)
for x in xrange(xrange_num):
p.spawn(down, geturl)
p.join()
print time.time()-start2
raw_input()
1 条回复 • 2017-03-08 16:05:22 +08:00
|
|
1
isofia 2017-03-08 16:05:22 +08:00
竟然一个回复都没有
|