Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: Is there a way to keep the dev server from restarting when a local .py file is changed and dynamically loaded?

In Django (1.9) trying to load .py files (modules) dynamically (via importlib). The dynamic reload is working like a charm, but every time I reload a module, the dev server restarts, having to reload everything else.

I'm pulling in a lot of outside data (xml) for testing purposes, and every time the environment restarts, it has to reload all of this external xml data. I want to be able to reload a module only, and keep that already loaded xml data intact, so that it doesn't have to go through that process every time I change some py-code.

Is there a flag I can set/toggle (or any other method) to keep the server from restarting the whole process for this single module reload?

Any help very appreciated.

like image 706
CodaRuner Avatar asked Apr 05 '16 08:04

CodaRuner


People also ask

Which of the following command is used to disable auto reloading of code while the development server is running?

Use the --noreload option to disable the use of the auto-reloader. This means any Python code changes you make while the server is running will not take effect if the particular Python modules have already been loaded into memory. The development server is multithreaded by default.

How do I stop Django running?

Though the message in the console states that Ctrl+Break should be used to quit the server, it is not possible; one can only use Ctrl+F4 works to close the console.

What server does Django use for development?

Django's primary deployment platform is WSGI, the Python standard for web servers and applications. Django's startproject management command sets up a minimal default WSGI configuration for you, which you can tweak as needed for your project, and direct any WSGI-compliant application server to use.


1 Answers

If you run the development server using --noreload parameter it will not auto reload the changes:

python manage.py runserver --noreload 

Disables the auto-reloader. This means any Python code changes you make while the server is running will not take effect if the particular Python modules have already been loaded into memory.

like image 175
Selcuk Avatar answered Sep 27 '22 22:09

Selcuk