Some more usability additions to the ProcPool system. Also made it default

to turned off when SQLite3 is used - SQLite3 doesn't support multiple
processes.
This commit is contained in:
Griatch 2012-09-02 18:57:25 +02:00
parent 575d7a86fa
commit 275d00d4db
2 changed files with 15 additions and 2 deletions

View file

@ -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.

View file

@ -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