def updateDb():
while True:
if len(params) != 0:
try:
dbconn = sqlite3.connect(dbpath)
cursor = dbconn.cursor()
for param in params:
cursor.execute(param['sql'], param['data'])
dbconn.commit()
cursor.close()
dbconn.close()
except Exception as e:
print e
time.sleep(10)
class threadPool(object):
workers = 10
jobs = []
def __init__(self):
for index in range(0, self.workers):
self.jobs.append(None)
def add(self, job):
while True:
for index in range(0, self.workers):
if self.jobs[index] is None or not self.jobs[index].isAlive():
self.jobs[index] = job
job.start()
return
time.sleep(0.5)
def end(self):
for job in self.jobs:
if job is not None:
job.join()
if __name__ == '__main__':
lock = threading.Lock()
pool = threadPool()
threading.Thread(target=updateDb, args=()).start()
# 18
for num in range(18, 10000):
pool.add(threading.Thread(target=doPost, args=(num,)))
pool.end()
time.sleep(10) cardata.rar(1.11 MB, 下载次数: 1)