python 遇到的各种坑

た 入场券 2023-06-20 04:56 25阅读 0赞

错误: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

参考样例,亲测可以

  1. with ThreadPoolExecutor(max_workers=3) as executor:
  2. future_tasks = [executor.submit(函数,迭代参数,非迭代参数)for 迭代参数 in 迭代参数数组]
  3. for future in as_completed(future_tasks): # 迭代生成器
  4. try:
  5. future.result()
  6. except Exception as e:
  7. print('%s' % e)
  8. # 获取campaign的成效数据
  9. with ThreadPoolExecutor(max_workers=3) as executor:
  10. executor.map(函数,迭代参数数组)

发表评论

表情:
评论列表 (有 0 条评论,25人围观)

还没有评论,来说两句吧...

相关阅读

    相关 python数据分析遇到

    持续了好长时间,看了python的底层源码,弄了多少个时辰,终于解决这个坑了。 话说这个坑是样的,用python读取csv文件,或者txt文件,发现索引怎么都对应不上,因为在