python 多线程

# -*- coding: UTF-8 -*-
 
import thread
import time
import urllib2
import httplib
import sys

def call():
    req  = urllib2.Request('http://jbheiruh.cn.com/?6NUPoA=nsFZjt2EEfKVhiw8V76B&page=UEFsaXBheQ==')
    f = urllib2.urlopen(req)
    response = f.read()
    f.close()

# 为线程定义一个函数
def print_time(threadName, delay):
    while True:
        call()
 
# 创建两个线程
try:
    count = 0
    while count < 10000:
        thread.start_new_thread(print_time, ("Thread-1", 2,))
        thread.start_new_thread(print_time, ("Thread-2", 4,))
except:
    print "Error: unable to start thread"

  

嗯,就这么玩一玩

posted @ 2018-09-28 00:25  佚名000  阅读(107)  评论(0)    收藏  举报