Home > other >  In Django running web applications using parallel ProcessPoolExecutor error: Apps aren 't the l
In Django running web applications using parallel ProcessPoolExecutor error: Apps aren 't the l

Time:03-12

The view in the Django framework to realize an interface has the following a few lines of code:

With concurrent. Futures. ProcessPoolExecutor () as executor:
Executor. Submit (fn)

Fn function refers to the Django model object
When a new process to load when the model error:
Django. Core. Exceptions. AppRegistryNotReady: Apps aren 't the loaded yet.

New process without the original process Apps information

Running Django underlying trigger Django. The setup ()

The following is the original code:
Def setup (set_prefix=True) :
"" "
Configure the Settings (this happens as a side effect of accessing the
The first setting), configure logging and populate the app registry.
Set the thread - local urlresolvers script prefix if ` set_prefix ` is True.
"" "
The from the django. Apps import apps
The from the django. Conf import Settings
The from the django. Urls import set_script_prefix
The from the django. Utils. The log import configure_logging

Configure_logging (Settings. LOGGING_CONFIG Settings. LOGGING)
If set_prefix:
Set_script_prefix (
'/' if Settings. FORCE_SCRIPT_NAME is None else Settings. FORCE_SCRIPT_NAME
)

# here is apps registration method, but the conclusion is only effective for the current process
Apps. The populate (Settings. The INSTALLED_APPS)

Could you tell me how in multiple processes sharing Django apps information

CodePudding user response:

Try with concurrent. Futures. ThreadPoolExecutor () as executor:
Executor. Submit (fn)
Or,

Executor. The map (fn)


Memory, the submit dispute blocking type,

CodePudding user response:

reference 1/f, love na ji reply:
try with concurrent. Futures. The ThreadPoolExecutor () as executor:
Executor. Submit (fn)
Or,

Executor. The map (fn)


Memory, the submit dispute blocking type,


Because ThreadPoolExecutor is still in the original process, so the concurrent can perform normal

But ProcessPoolExecutor parallel will create a new process, the process of different apps information isolation between the

  • Related