diff --git a/lib/galaxy/app.py b/lib/galaxy/app.py index 39be835f02ee..7008e4a5e766 100644 --- a/lib/galaxy/app.py +++ b/lib/galaxy/app.py @@ -159,7 +159,7 @@ def __init__(self, **kwargs): self.datatypes_registry.load_external_metadata_tool(self.toolbox) # Load history import/export tools. load_lib_tools(self.toolbox) - self.toolbox.persist_cache() + self.toolbox.persist_cache(register_postfork=True) # visualizations registry: associates resources with visualizations, controls how to render self.visualizations_registry = VisualizationsRegistry( self, diff --git a/lib/galaxy/tools/__init__.py b/lib/galaxy/tools/__init__.py index 5330f891d3f5..8b61dfe81373 100644 --- a/lib/galaxy/tools/__init__.py +++ b/lib/galaxy/tools/__init__.py @@ -261,9 +261,19 @@ def __init__(self, config_filenames, tool_root_dir, app, save_integrated_tool_pa save_integrated_tool_panel=save_integrated_tool_panel, ) - def persist_cache(self): + def persist_cache(self, register_postfork=False): + """ + Persists any modified tool cache files to disk. + + Set ``register_postfork`` to stop database thread queue, + close database connection and register re-open function + that re-opens the database after forking. + """ for region in self.cache_regions.values(): region.persist() + if register_postfork: + region.close() + self.app.application_stack.register_postfork_function(region.reopen_ro) def can_load_config_file(self, config_filename): if config_filename == self.app.config.shed_tool_config_file and not self.app.config.is_set('shed_tool_config_file'): diff --git a/lib/galaxy/tools/cache.py b/lib/galaxy/tools/cache.py index 042ae776bfda..37ee95f013a5 100644 --- a/lib/galaxy/tools/cache.py +++ b/lib/galaxy/tools/cache.py @@ -43,6 +43,13 @@ def __init__(self, cache_dir): # Switch SqliteDict back to readonly self._cache.flag = 'r' + def close(self): + self._cache.close() + + def reopen_ro(self): + self._cache = SqliteDict(self.cache_file, flag='r', encode=encoder, decode=decoder, autocommit=False) + self.writeable_cache_file = None + def get(self, config_file): tool_document = self._cache.get(config_file) if not tool_document: @@ -65,8 +72,7 @@ def persist(self): if self.writeable_cache_file: self._cache.commit() os.rename(self.writeable_cache_file.name, self.cache_file) - self._cache = SqliteDict(self.cache_file, flag='r', encode=encoder, decode=decoder, autocommit=False) - self.writeable_cache_file = None + self.reopen_ro() def set(self, config_file, tool_source): self.make_writable()