【问题标题】:playhouse.pool.MaxConnectionsExceeded: Exceeded maximum connectionsc with multithreadingplayhouse.pool.MaxConnectionsExceeded:超过了多线程的最大连接数
【发布时间】:2020-11-08 19:17:15
【问题描述】:

我有数据,我想通过将它们分成 4 个线程来编写我的代码。例如: 当我有 100 个对象时,我会将它们划分为 25-25-25-25。也许,我会有 2 个对象。在这种情况下,两个线程应该可以工作。

我在下面写了代码

for item in all_strategy_ids:
            p1 = threading.Thread(target=self.proccess,args=(item.id,))
            p2 = threading.Thread(target=self.proccess,args=(item.id,))
            p3 = threading.Thread(target=self.proccess,args=(item.id,))
            p4 = threading.Thread(target=self.proccess,args=(item.id,))
            p1.start()
            p2.start()
            p3.start()
            p4.start()
            p1.join()
            p2.join()
            p3.join()
            p4.join()

而且,我正在使用 peewee。我在 peewee 连接下方添加了这个

 max_connections=8,stale_timeout=300,

但是,我收到此错误:

raise MaxConnectionsExceeded('Exceeded maximum connections.')
playhouse.pool.MaxConnectionsExceeded: Exceeded maximum connections.


那么,问题是我该如何解决这个问题?

【问题讨论】:

    标签: python python-3.x multithreading threadpool peewee


    【解决方案1】:

    如果您正在使用连接池,那么您需要确保在使用完连接后立即关闭

    由于您忽略了与初始化连接相关的任何代码,因此很难说问题出在哪里。只要确保你在线程开始时连接并在它返回之前关闭就可以了。

    请阅读文档,尤其是粗体部分:

    http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#connection-pool

    【讨论】:

      猜你喜欢
      • 2012-02-17
      • 2015-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多