Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Development

Notices

Reply
 
Thread Tools Search this Thread
Old 10-18-2019, 09:16 AM   #1
thiago.eec
Guru
thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.
 
Posts: 947
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
This message does not prevent the plugin to work. If the user selects up to around 20/25 books, calibre will show this message twice. If more books are selected, then it starts showing it more and more. With bigger selections, like 50 books, the message is shown 10/20 times. Sometimes, despite all the messages, the plugin still completes his job. But many times, calibre crashes.

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?
Attached Files
File Type: zip Skoob_Sync.zip (173.0 KB, 249 views)
thiago.eec is offline   Reply With Quote
Old 10-18-2019, 10:16 AM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 44,062
Karma: 22669822
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.
kovidgoyal is offline   Reply With Quote
Advert
Old 10-18-2019, 11:38 AM   #3
thiago.eec
Guru
thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.
 
Posts: 947
Karma: 1183425
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite
Quote:
Originally Posted by kovidgoyal View Post
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.
Thanks a lot, Kovid.

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!

thiago.eec is offline   Reply With Quote
Reply

Tags
multithread, threads


Forum Jump

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


All times are GMT -4. The time now is 02:59 AM.


MobileRead.com is a privately owned, operated and funded community.