场景如下所示,我有很多进程要做 CPU 密集型工作并且只在同一个数据库上读取,我知道缓存和 uri 关键字可用于 sqlite 在线程之间共享数据库缓存,但是进程之间呢?最好同时适用于 linux 和 windows,谢谢!
def run(self):
self.phyconn = apsw.Connection(self.fileName)
self.memconn = apsw.Connection(":memory:")
try:#backup.__exit__() just make sure copy if finished,not close backup,so with is good,memconn is still exist when out
with self.memconn.backup("main", self.phyconn, "main") as backup:
# call with 0 to get the total pages
backup.step(0)
total = backup.pagecount
stepped = 0
one_percent = total if total < 100 else total // 100
last_percentage = 0
while stepped <= total:
if self.cancel:
#self.progressCanceled.emit()
self.memconn=None
return
backup.step(one_percent)
stepped = stepped + one_percent
stepped_percentage = stepped*100//total
if stepped_percentage != last_percentage:
last_percentage = stepped_percentage
#self.progressChanged.emit(stepped_percentage)
websocket.UpdateLoadDBProgress(stepped_percentage,self.sid)
这不可能。if 进程的全部意义在于将它们的内存彼此隔离。(大多数操作系统允许共享内存,但没有可移植的机制。)
即使有可能,它也不会更快,因为 SQLite 和操作系统都会缓存数据。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句