mirror of
https://github.com/slgobinath/SafeEyes.git
synced 2025-01-01 00:47:31 +01:00
Initialize thread pool only if there are plugins
This commit is contained in:
parent
5e9f68ff44
commit
a1b3f6e094
@ -35,7 +35,6 @@ class Plugins:
|
||||
"""
|
||||
logging.info('Load all the plugins')
|
||||
self.__plugins = []
|
||||
self.__thread_pool = ThreadPool(4)
|
||||
|
||||
for plugin in config['plugins']:
|
||||
if plugin['location'].lower() in ['left', 'right']:
|
||||
@ -50,11 +49,16 @@ class Plugins:
|
||||
else:
|
||||
logging.warning('Ignoring the plugin ' + str(plugin['name']) + ' due to invalid location value: ' + plugin['location'])
|
||||
|
||||
print(min([4, len(self.__plugins)]))
|
||||
if self.__plugins:
|
||||
self.__thread_pool = ThreadPool(min([4, len(self.__plugins)]))
|
||||
|
||||
|
||||
def start(self, context):
|
||||
"""
|
||||
Call the start function of all the plugins in separate thread.
|
||||
"""
|
||||
if self.__plugins:
|
||||
context = copy.deepcopy(context) # If plugins change the context, it should not affect Safe Eyes
|
||||
for plugin in self.__plugins:
|
||||
try:
|
||||
@ -66,6 +70,7 @@ class Plugins:
|
||||
"""
|
||||
Call the pre_notification function of all the plugins in separate thread.
|
||||
"""
|
||||
if self.__plugins:
|
||||
context = copy.deepcopy(context) # If plugins change the context, it should not affect Safe Eyes
|
||||
for plugin in self.__plugins:
|
||||
try:
|
||||
@ -81,6 +86,7 @@ class Plugins:
|
||||
|
||||
Returns: {'left': 'Markup of plugins to be aligned on left', 'right': 'Markup of plugins to be aligned on right' }
|
||||
"""
|
||||
if self.__plugins:
|
||||
context = copy.deepcopy(context) # If plugins change the context, it should not affect Safe Eyes
|
||||
output = {'left': ' \n', 'right': ' \n'}
|
||||
multiple_results = [self.__thread_pool.apply_async(plugin['module'].pre_break, (context,)) for plugin in self.__plugins]
|
||||
@ -105,6 +111,7 @@ class Plugins:
|
||||
"""
|
||||
Call the post_break function of all the plugins in separate thread.
|
||||
"""
|
||||
if self.__plugins:
|
||||
context = copy.deepcopy(context) # If plugins change the context, it should not affect Safe Eyes
|
||||
for plugin in self.__plugins:
|
||||
try:
|
||||
@ -116,6 +123,7 @@ class Plugins:
|
||||
"""
|
||||
Call the exit function of all the plugins in separate thread.
|
||||
"""
|
||||
if self.__plugins:
|
||||
context = copy.deepcopy(context) # If plugins change the context, it should not affect Safe Eyes
|
||||
|
||||
# Give maximum 1 sec for all plugins before terminating the thread pool
|
||||
|
Loading…
Reference in New Issue
Block a user