mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Do not initialize the user defined driver plugin in worker processes
This commit is contained in:
parent
efcb589b19
commit
7396d7a69d
@ -452,6 +452,9 @@ def device_plugins(include_disabled=False): # {{{
|
||||
if isinstance(plugin, DevicePlugin):
|
||||
if include_disabled or not is_disabled(plugin):
|
||||
if platform in plugin.supported_platforms:
|
||||
if getattr(plugin, 'plugin_needs_delayed_initialization',
|
||||
False):
|
||||
plugin.do_delayed_plugin_initialization()
|
||||
yield plugin
|
||||
# }}}
|
||||
|
||||
@ -496,7 +499,7 @@ def initialize_plugin(plugin, path_to_zip_file):
|
||||
def has_external_plugins():
|
||||
return bool(config['plugins'])
|
||||
|
||||
def initialize_plugins():
|
||||
def initialize_plugins(perf=False):
|
||||
global _initialized_plugins
|
||||
_initialized_plugins = []
|
||||
conflicts = [name for name in config['plugins'] if name in
|
||||
@ -505,6 +508,10 @@ def initialize_plugins():
|
||||
remove_plugin(p)
|
||||
external_plugins = config['plugins']
|
||||
ostdout, ostderr = sys.stdout, sys.stderr
|
||||
if perf:
|
||||
from collections import defaultdict
|
||||
import time
|
||||
times = defaultdict(lambda:0)
|
||||
for zfp in list(external_plugins) + builtin_plugins:
|
||||
try:
|
||||
if not isinstance(zfp, type):
|
||||
@ -517,7 +524,11 @@ def initialize_plugins():
|
||||
plugin = load_plugin(zfp) if not isinstance(zfp, type) else zfp
|
||||
except PluginNotFound:
|
||||
continue
|
||||
if perf:
|
||||
st = time.time()
|
||||
plugin = initialize_plugin(plugin, None if isinstance(zfp, type) else zfp)
|
||||
if perf:
|
||||
times[plugin.name] = time.time() - st
|
||||
_initialized_plugins.append(plugin)
|
||||
except:
|
||||
print 'Failed to initialize plugin:', repr(zfp)
|
||||
@ -526,6 +537,9 @@ def initialize_plugins():
|
||||
# Prevent a custom plugin from overriding stdout/stderr as this breaks
|
||||
# ipython
|
||||
sys.stdout, sys.stderr = ostdout, ostderr
|
||||
if perf:
|
||||
for x in sorted(times, key=lambda x:times[x]):
|
||||
print ('%50s: %.3f'%(x, times[x]))
|
||||
_initialized_plugins.sort(cmp=lambda x,y:cmp(x.priority, y.priority), reverse=True)
|
||||
reread_filetype_plugins()
|
||||
reread_metadata_plugins()
|
||||
|
@ -90,6 +90,10 @@ class USER_DEFINED(USBMS):
|
||||
OPT_CARD_A_FOLDER = 9
|
||||
|
||||
def initialize(self):
|
||||
self.plugin_needs_delayed_initialization = True
|
||||
USBMS.initialize(self)
|
||||
|
||||
def do_delayed_plugin_initialization(self):
|
||||
try:
|
||||
e = self.settings().extra_customization
|
||||
self.VENDOR_ID = int(e[self.OPT_USB_VENDOR_ID], 16)
|
||||
@ -107,4 +111,6 @@ class USER_DEFINED(USBMS):
|
||||
except:
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
USBMS.initialize(self)
|
||||
self.plugin_needs_delayed_initialization = False
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user