龙少的多线程并发注册用户代码:
import random import urllib2 import urllib import threading from time import ctime,sleep user_password= "!QAZ2wsx" url = "http://192.168.104.100:8090/mental/auth/user/register/" def create_random_sr(num=11): s="" while (num>0): tmp=random.randint(0,9) s += str(tmp) num=num-1 return s def send_post_request(email,tel): req = urllib2.Request(url,urllib.urlencode({"email":email,"password":user_password,"repeat_password":user_password,"tel":tel})) req.add_header("Referer",url) resp = urllib2.urlopen(req) print resp.read() count=1 threads=[] _mid_str = create_random_sr(5) email = "test"+_mid_str+"@qq.com" tel = create_random_sr(11) while(count>0): t= threading.Thread(target=send_post_request,args=(email,tel)) threads.append(t) count = count -1 if __name__ == '__main__': for t in threads: t.setDaemon(True) t.start() t.join() print "all over %s" %ctime()