View Single Post
Old 01-03-2016, 06:47 AM   #1
Phssthpok
Age improves with wine.
Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.
 
Posts: 580
Karma: 95229
Join Date: Nov 2014
Device: Kindle Oasis, Kobo Libra II
Advice needed for plugin running background thread

As described in another thread I'm thinking of writing a plugin to reset permissions on files in the auto-add directory so they don't get stuck there for weeks until I manually reset them. (The rights and wrongs of it are discussed extensively in that thread, but I feel like trying it anyway, as an exercise if nothing else.)

The idea is to have a plugin which spins off a background thread when Calibre starts up, which shuts down when Calibre shuts down. I was thinking of something along the following lines:
Code:
class MyPlugin(Plugin):
    keepRunning = True
    def threadBody():
        while keepRunning:
            ...
    def __init__(self):
        thread = new Thread(target=threadBody)
        thread.start()
Can anyone advise me:
(a) am I going about this in the right way -- that is, will this do what I want?
(b) what are the lifecycle issues I need to deal with (i.e. setting my keepRunning flag to False to shut down the thread in an orderly way; handling plugin reloads or whatever) and how do I deal with them?
(c) is there anything else I should know before I dive in (apart from RTFM, of course)?

I've never written a plugin before, so feel free to tell me I'm a complete idiot!

Last edited by Phssthpok; 01-03-2016 at 07:15 AM.
Phssthpok is offline   Reply With Quote