【发布时间】: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