diff --git a/src/settings_default.py b/src/settings_default.py index 09266b5d14..37fe268fa0 100644 --- a/src/settings_default.py +++ b/src/settings_default.py @@ -347,7 +347,11 @@ RSS_UPDATE_INTERVAL = 60*10 # 10 minutes # multiple processes). But it may be slower for some # combinations of database and operating system. Also, creating # objects from another process will require re-syncing of caches. -PROCPOOL_ENABLED = False +# ProcPool is disabled by default on SQlite3 since it cannot handle +# multiple process-writes very well. It should work fine with other supported +# databases. If you plan to change your database, copy the following line +# to your settings file to have it deactivate automatically for sqlite3. +PROCPOOL_ENABLED = not DATABASES["default"]["ENGINE"] == 'django.db.backends.sqlite3' # relay process stdout to log (debug mode, very spammy) PROCPOOL_DEBUG = False # max/min size of the process pool. Will expand up to max limit on demand. diff --git a/src/utils/utils.py b/src/utils/utils.py index ca307f6de5..55d4be8e2b 100644 --- a/src/utils/utils.py +++ b/src/utils/utils.py @@ -557,6 +557,13 @@ def run_async(to_execute, *args, **kwargs): enabled, if not this will raise a RunTimeError. reserved kwargs: + 'use_thread' (bool) - this only works with callables (not code). + It forces the code to run in a thread instead + of using the Process Pool, even if the latter + is available. This could be useful if you want + to make sure to not get out of sync with the + main process (such as accessing in-memory global + properties) 'at_return' -should point to a callable with one argument. It will be called with the return value from to_execute. @@ -635,13 +642,15 @@ def run_async(to_execute, *args, **kwargs): _LOGGER.log_errmsg(err) return func + use_thread = kwargs.pop("use_thread", False) + # handle special reserved input kwargs callback = convert_return(kwargs.pop("at_return", None)) errback = convert_err(kwargs.pop("at_err", None)) callback_kwargs = kwargs.pop("at_return_kwargs", {}) errback_kwargs = kwargs.pop("at_err_kwargs", {}) - if _PPOOL: + if _PPOOL and not use_thread: # process pool is running if isinstance(to_execute, basestring): # run source code in process pool