|
|
Thread Tools | Search this Thread |
10-18-2019, 09:16 AM | #1 |
Guru
Posts: 956
Karma: 1183425
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite
|
QObject::setParent: Cannot set parent, new parent is in a different thread
Hi, everyone.
I've created this plugin to sync calibre library and Skoob (a book social network, similar to GoodReads). Skoob does not have a public API, so I had to scrape the website for data. The plugin logs in to Skoob and get the user data (progress, review, etc). For better performance when fetching data, I used two strategies: 1) Keep a cookie, with an open session. This way, only the first 'click' will trigger the login. After that, if any function is used while calibre is still open, it will use the stored cookie and we gain a couple of seconds. OBS.: I could not find a way to make the cookie work after restarting calibre. 2) When selecting multiple books, each one is processed on a different thread. This really speeds up the task, since every book is processed in parallel. Although, here also lies the problem... When the user selects a couple of books, calibre shows this error/warning on the debug log: Code:
QObject::setParent: Cannot set parent, new parent is in a different thread I've tried to pinpoint what may be the cause for this, but I could not find it. So, I got around it using time delays. Initially, I had set a time.sleep(0.1) between each thread. Now, I've added a time.sleep(2) between every 20 books. This seems to avoid calibre crashing, but all the messages are still there. Any hints? |
10-18-2019, 10:16 AM | #2 |
creator of calibre
Posts: 44,190
Karma: 23000010
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
You should only use Qt objects on a single thread. There is a way to transfer objects from onethread to another, but I would not bother. Instead have your worker threads emit signals with data in some non Qt object form, like a python dit or whatever and have the main thread convert it into needed Qt objects.
|
Advert | |
|
10-18-2019, 11:38 AM | #3 | |
Guru
Posts: 956
Karma: 1183425
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite
|
Quote:
That gave me the clue where to find the problem: I had a message showing in the status bar that was being set inside the thread. I moved it outside and everything is fine now! |
|
Tags |
multithread, threads |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
TOC section scope is not included in the parent chapter | feraudyh | Sigil | 3 | 12-26-2016 06:02 AM |
Get metadata from parent folders | wladdy | Library Management | 4 | 03-11-2015 04:49 PM |
Kobo's Parent Company: Guilty of Credit Card Fraud? | Prestidigitweeze | News | 17 | 08-18-2013 12:27 PM |
Easiest ereader for older parent to use | demingite | Which one should I buy? | 24 | 11-27-2010 01:16 PM |
Astak Parent Company website | Robertb | Astak EZReader | 29 | 02-25-2010 09:07 PM |