代码拉取完成,页面将自动刷新
import threading
import queue
from collections import deque
from sqlhand import DbHandle
from toolhand import *
class MultiGetUrl(threading.Thread):
def __init__(self, task_queue, thread_name, logger, lock):
threading.Thread.__init__(self, name=thread_name)
self.queue = task_queue
self.lock = lock
self.logger = logger
self.tmp = []
def run(self):
while True:
info = self.queue.get()
if self.lock.locked():
self.tmp.append(info)
pass
else:
self.lock.acquire()
db = DbHandle(self.logger)
dbfile = "todayb.db"
db.db_connect(dbfile)
db.init_database()
print(info, self.getName())
for tt in self.tmp:
'''allstar(tt, db)'''
self.tmp = []
self.lock.release()
self.queue.task_done()
def main():
start = dict()
start['url'] = "https://www.nsfw.xxx"
logop = dict()
logop['logFile'] = "log.txt"
logop['logLevel'] = "INFO"
global global_logger
global_logger = getlog(logop)
global global_db
global_db = DbHandle(global_logger)
dbfile = "todayb.db"
global_db.db_connect(dbfile)
global_db.init_database()
'''global_db.select_urls()'''
global_db.insert_one(start, 'urls')
global_queue = queue()
thread_num = 3
lock = threading.Lock()
for i in range(thread_num):
print("thread:", i)
t1 = MultiGetUrl(queue, 'urlt_' + str(i), global_logger, lock)
t1.setDaemon(True)
t1.start()
allurl = global_db.select_urls()
while True:
print("in main while")
while len(allurl) > 0:
t = allurl.pop()
print(t)
global_queue.put(t)
allurl = global_db.select_urls()
global_queue.join()
if __name__ == "__main__":
print("hello world\n")
main()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。