python-3.x - 不能将 SQLite Row 对象与多处理库一起使用
问题描述
我正在尝试学习如何在 Python 中使用 SQLite 和多处理库。也许我的问题很简单,但我不知道如何更改我的程序以使其正常工作。
我有以下代码:
import multiprocessing
import time
from db import get_db
def _getDbData():
db = get_db()
rows = db.execute('SELECT * FROM table')
return rows.fetchall()
def _taskPut(row_tuple, queue, flag):
for i in range(5):
queue.put((row_tuple[0], i))
print(' * inserted values: ', row_tuple[0], i)
time.sleep(0.75)
def _taskGet(queue):
while queue.qsize():
print(queue.get())
def runTasks():
consoles= _getDbData()
with multiprocessing.Manager() as process_mgr:
# Create shared Queue and iterable with function arguments
events_queue= process_mgr.Queue()
args= zip( [tuple(i) for i in consoles], [events_queue]*len(consoles), [False]*len(consoles) )
pool= multiprocessing.Pool()
pool.map(_taskPut, zip(consoles, args))
pool.map(_takGet, (events_queue,))
pool.close()
pool.join()
我收到错误:TypeError: can't pickle sqlite3.Row objects
。我不明白为什么会出现此错误,因为我没有通过sqlite3.Row
但是tuple
.
PS:如果我的英语不完美,请见谅。我不是母语人士。还有函数_taskPut
和_taskGet
是虚拟函数,因为我只是想测试多处理是如何工作的。
解决方案
推荐阅读
- excel - Powershell 脚本使用管道分隔符和文本限定符将 excel 转换为 csv
- python - Tortoise ORM - 具有 Postgresql 时间字段的 Pydantic 模型
- node.js - 有没有办法在插入后立即返回文档?
- gspread - Gspread append 没有删除单引号
- react-native - 我应该如何在嵌套组件中使用钩子
- c++ - C1010: 查找预编译头文件时意外结束。您是否忘记将 '#include "pch.h"' 添加到您的源代码中?即使它在那里
- python - 如何在 Python 中使用 NordVPN?
- bash - 带倒计时线的 while 循环
- javascript - TypeError:n.split 不是函数
- php - MariaDB with PHP: SQLSTATE[HY000] [2002] Connection refused