|
|
#1 |
|
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,216
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
apsw.ThreadingViolationError and cache.write_lock
I have a plugin (Last Modified Plugin) that updates date columns in response to to database events. One problem I am facing is that when mulitple database events are happening in succession (e.g. adding multiple books), I sometimes get a variety of apsw.ThreadingViolationError, as illustrated below:
Spoiler:
I tried multiple solutions for this (e.g. using QTimer.singleShot, FunctionDispatcher and a combination of both), but the only solution that seems to be working for me is by using a cache.write_lock as illustrated in the code below: Code:
def update_date_column(self, cache, col, timestamp, book_ids):
if DEBUG:
prints('Last Modified Plugin: Update column ({}) for book_ids: {}'.format(col, book_ids))
id_map = {book_id: timestamp for book_id in book_ids}
f = cache.fields[col]
with cache.write_lock:
f.writer.set_books(id_map, cache.backend)
|
|
|
|
|
|
#2 |
|
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,616
Karma: 28549044
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Just use
cache.set_field() |
|
|
|
| Advert | |
|
|
|
|
#3 |
|
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,216
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
OK. I went for set_books() to avoid triggering events for date fields updated by the plugin. But I can solve this by caching timestamps for updated date fields and dropping any events triggered for the said columns shortly after. Thanks for your reply.
|
|
|
|
![]() |
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Calibre cache | thiago.eec | Calibre | 14 | 03-31-2022 07:57 AM |
| Viewer Cache | 8bulochka8 | Viewer | 6 | 02-18-2021 12:17 PM |
| How to clear cache? | odamizu | Kindle Developer's Corner | 8 | 04-11-2017 12:15 PM |
| The py27-apsw | fontes31 | Devices | 0 | 06-26-2016 02:05 PM |
| Do recipes use a cache? | Starson17 | Calibre | 2 | 03-10-2010 11:05 PM |