为了提高效率,刚开始用了多线程 threading 和协程 gevent ,但因为其他原因,后来又取消了线程,改用了多进程,multiprocessing库,代码如下,结果运行时到最后一步卡死了,后来花了三四天才找到原因,原来是用协程时用了猴子补丁monkey patch,但是改用进程时忘记删掉了,导致程序卡死,删掉引用的线程和协程库以及猴子补丁monkey patch就可以正常运行了。
import gevent
from gevent import monkey, pool
monkey.patch_all()
import requests, time, queue, json,os
import multiprocessing
class Baidu:
def __init__(self):
self.headers = {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,ja;q=0.7",
"Cache-Control": "max-age=0",
"Connection": "keep-alive",