python 遇到的各种坑

错误:unbound method read() must be called with RawConfigParser instance as first argument (got str instance instead)

解答:因为read不是静态方法,所以必须实例化才能使用

错误:ValueError: dictionary update sequence element #0 has length 1; 2 is required

解答:字典和字符串的转换,不单单是指str() dict()之间的转换,即使这样做,也会继续报这个错误

字符串和字典的转换要用eval()

peewee 使用报错 peewee.InterfaceError: (0, '')
经查原因是需要添加数据库连接池,长连接导致没有了连接

peewee 使用报错 Exceed max connections 连接池满了:

  背景: 使用playhouse链接池,加断开重连应用于多线程

使用database.connection_context()在使用万链接自动断开,依旧会出现这样的错误

ThreadPoolExexutor 的使用

如果我们要使用的方法是要传递一个需要迭代的参数,可以使用map

如果有固定的参数和迭代的参数,可以使用submit

参考样例,亲测可以

    with ThreadPoolExecutor(max_workers=3) as executor:
        future_tasks = [executor.submit(函数,迭代参数,非迭代参数)for 迭代参数 in 迭代参数数组]
        for future in as_completed(future_tasks):  # 迭代生成器
            try:
                future.result()
            except Exception as e:
                print('%s' % e)
    # 获取campaign的成效数据
    with ThreadPoolExecutor(max_workers=3) as executor:
        executor.map(函数,迭代参数数组)
        
发布了41 篇原创文章 · 获赞 4 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_37992974/article/details/103437831