def receive_thread(number):
srv = POP3(host=self.url, timeout=5)
srv.user(email_name)
srv.pass_(email_pwd)
rsp, lines, octets = srv.retr(number)
msg_byte = b'\r\n'.join(lines)
msg_content = msg_byte.decode(chardet.detect(msg_byte)['encoding'])
msg = Parser().parsestr(msg_content)
def email_download():
with ThreadPoolExecutor(max_workers=6) as pool:
numbers =200
futures = [pool.submit(receive_thread, i) for i in range(numbers, 0, -1)]
for future in futures:
print(future.result())
t1 = threading.Thread(target=email_download)
t1.start()
只要带有网络请求的就会被阻塞,导致线池的线程被阻塞了,程序退出了,线程没有退出求解决方案,谢谢!
t1.setDaemon(True)
设置这个没有用
@PoppinDream:
没看到还有用到 ThreadPoolExecutor,这种情况用 shutdownNow() 手动关闭线程池就是了。
注意:调用ShutdownNow()并不能百分百保证线程池就一定能立即退出,但是大多数时候是可以的。要百分百控制保证,只有给每个任务加一个立即结束的机制了。