View Single Post
Old 12-15-2014, 09:37 PM   #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: 45,382
Karma: 27756918
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
In __init__ or at the module level. Or simply use a global variable to check that the initialization has been performed.

And note that, for file type plugins, the plugin is run in a worker process, which means initialization including __init__ will happen once per worker process (and note that there can be multiple worker processes, and new worker processes can be created at any time). So if you are doing some initialization that needs to occur only once, not once per processes, you will need to use some kind of IPC locking mechanism, like a sentinel directory or a lock file or a global mutex.

Last edited by kovidgoyal; 12-15-2014 at 09:40 PM.
kovidgoyal is offline   Reply With Quote