放弃队列线程了

master
wkyuu 3 years ago
parent 8ca463292a
commit e5d47a8d55

@ -1,2 +0,0 @@
# -*- coding: utf-8 -*-

@ -17,6 +17,7 @@ BASEURL = settings.BASEURL
FILENAME_CSV = settings.FILENAME_CSV
threadLock = threading.Lock()
threadlines = 16 # 默认调用16个线程不要超过20
flag = 1 # 判断主线程
connection_pool = redis.ConnectionPool(host = REDIS_HOST, port = REDIS_PORT, password = REDIS_PASSWORD, decode_responses = True)
redisconn = redis.Redis(connection_pool = connection_pool)
@ -77,14 +78,12 @@ class milkSpider(threading.Thread):
def run(self):
self.response = downloader.getsource(self.url)
threadLock.acquire()
# print("write2csv for '{}' will be started in 3 seconds....".format(self.url))
print("write2csv for '{}' was started.".format(self.url))
# time.sleep(3)
write2csv(self.category, self.response)
print("{} is done.".format(self.name))
threadLock.release()
def mainThread(threadlines = 16, flag = flag): # 线程数默认为3
def mainThread(threadlines = threadlines, flag = flag): # 线程数默认为3
try:
threads = []
for index in range(1, threadlines + 1):
@ -116,9 +115,6 @@ if __name__ == '__main__':
# 以下是本地测试
def print2console(response): # 输出到命令行
pipelines.print2console(response)

@ -7,11 +7,9 @@ def milkSpider():
if middlewares.precheck():
start_time = time.time()
middlewares.mainThread()
print("Totally spend " + str(time.time() - start_time) + "secends")
print("Totally spend " + str(round(time.time() - start_time, 2)) + " secends")
print("milkSpider done.")
if __name__ == "__main__":
milkSpider()

Loading…
Cancel
Save