While issuing management command runserver
, it runs the server with loader. In source code of Django1.5
came across a piece of code
where before staring a server in new process/thread , it specifically set the value of RUN_MAIN
to 'true'
in environment variable if its is not 'true'
django/utils/autoreload.py
new_environ = os.environ.copy()
new_environ["RUN_MAIN"] = 'true'
exit_code = os.spawnve(os.P_WAIT, sys.executable, args, new_environ)
In other piece of code it checks if that value value is being set ot not , if it is set then only it create a new process/thread.
if os.environ.get("RUN_MAIN") == "true":
thread.start_new_thread(main_func, args, kwargs)
by default in system(linux2) that value is not being set.
Queries:
1) what is the significance of that environment variable and how it is related to starting new process/thread.
2) if the "RUN_MAIN"
is 'true' then code creates a thread, otherwise it creates a process. why is that ?