设置线程为守护线程 随主线程结束而结束

This commit is contained in:
Jing Ling
2020-08-26 23:26:25 +08:00
parent eefa1ecd5b
commit 6062eb22dc
2 changed files with 5 additions and 5 deletions
+3 -2
View File
@@ -167,12 +167,13 @@ def bulk_request(urls):
thread_count = req_thread_count() thread_count = req_thread_count()
progress_thread = Thread(target=progress, name='ProgressThread', progress_thread = Thread(target=progress, name='ProgressThread',
args=(urls, resp_queue)) args=(urls, resp_queue), daemon=True)
progress_thread.start() progress_thread.start()
for i in range(thread_count): for i in range(thread_count):
request_thread = Thread(target=request, name=f'RequestThread-{i}', request_thread = Thread(target=request, name=f'RequestThread-{i}',
args=(urls_queue, resp_queue, session)) args=(urls_queue, resp_queue, session),
daemon=True)
request_thread.start() request_thread.start()
urls_queue.join() urls_queue.join()
+2 -3
View File
@@ -49,9 +49,8 @@ class Collect(object):
# Create subdomain collection threads # Create subdomain collection threads
for collect_func in self.collect_funcs: for collect_func in self.collect_funcs:
func_obj, func_name = collect_func func_obj, func_name = collect_func
thread = threading.Thread(target=func_obj, thread = threading.Thread(target=func_obj, name=func_name,
name=func_name, args=(self.domain,), daemon=True)
args=(self.domain,))
threads.append(thread) threads.append(thread)
# Start all threads # Start all threads
for thread in threads: for thread in threads: