为了提高性能,我尝试一次处理多条记录,因此首选多线程。每个线程都涉及数据库连接,我收到类似pymysql.err.InternalError: Packet sequence number wrong - got 48 expected 1 之类的错误
我在这里附上了我的代码示例。任何建议或真实答案都会有所帮助
items = items_array
if(items):
print(items);
ListOfProcesses = []
number_of_items = len(items)
processors = 20 # n of processors you want to use
parts = [items[i:i + processors] for i in range(0, len(items), processors)]
for part in parts:
for f in part:
p = Process(target=self.parallel_print, args=(f,))
p.start()
ListOfProcesses.append(p)
for p in ListOfProcesses:
p.join()
def parallel_print(self, item_code):
frappe.get_doc("Item", item_code)