35

I've just created new Python 3.7 virtualenv with Django 2.2

And each runserver it prints:

Watching for file changes with StatReloader

I could not find any info in Django's docs etc.

Is it related specially to Django somehow? Does it go with Django? What it does? Why is it printed in red in PyCharm? Should I be careful about something? Could it be disabled?

Big thx

MaxCore
  • 2,438
  • 4
  • 25
  • 43
  • 1
    You are right - there's [no doc for that](https://www.google.com/search?q=%22StatReloader%22+site%3Adjangoproject.com). Weird that django would do that. – Adelin Apr 24 '19 at 14:00

3 Answers3

26

Its the class that django uses to auto reload the development server whenever you make code changes .

Specifically, determined within the get_reloader method where watchman is an alternative for linux / macOS

If you’re using Linux or MacOS and install both pywatchman and the Watchman service, kernel signals will be used to autoreload the server (rather than polling file modification timestamps each second). This offers better performance on large projects, reduced response time after code changes, more robust change detection, and a reduction in power usage.

(Runserver docs)

No idea why its in red in pycharm but if you really wanted to you can disable it with the --noreload flag

Sayse
  • 42,633
  • 14
  • 77
  • 146
  • So, It was always there? Either I'm an idiot and didn't notice it before, either Django starts printing this message only since 2.2 – MaxCore Apr 24 '19 at 14:10
  • 3
    It wasn't always there. It [was added in Jan 2019](https://github.com/django/django/commit/c8720e7696ca41f3262d5369365cc1bd72a216ca#diff-46e69f287173eef41fcbfeba05501954) – Adelin Apr 24 '19 at 14:18
  • 3
    @MaxCore - Specifically, it was added on 14th Jan - ([Commit](https://github.com/django/django/commit/c8720e7696ca41f3262d5369365cc1bd72a216ca#diff-46e69f287173eef41fcbfeba05501954R577)), so yes, according to the [2.2 release notes](https://docs.djangoproject.com/en/2.2/releases/2.2/), it was added for 2.2, although auto reloading isn't a new feature – Sayse Apr 24 '19 at 14:18
8

in my case, I changed the option DEBUG= True for DEBUG=False in my file settings.py, since then its working.

before in settings.py:

#SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

in docker :

$ docker run  container_name 

Watching for file changes with StatReloader

after in settings.py:

#SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False 

in docker:

$ docker run container_name
[24/Mar/2020 10:10:19] "GET /health HTTP/1.1" 200 5299
  • 1
    Thank you for your answer! It would be very helpful, if you could provide some context as to why this solution solves the problem, so that people with similar problems can identify a solution from here. – creyD Mar 24 '20 at 14:18
  • 3
    @creyD it seems related with the tty; using `tty: true` in `docker-compose.yml` (or using `-t` as docker option) fixes the issue, even if `DEBUG` is set to `True`. – Francesco Frassinelli Sep 09 '20 at 02:38
  • @FrancescoFrassinelli Your suggestion finally fixed a problem in compose + django that was bugging me in multiple projects for months! This should be high up for all docker compose + django users. – Arvin Jan 13 '21 at 13:34
5

Use --noreload flag when running the development server

python manage.py runserver 0.0.0.0:8000 --noreload

Reference is here.

sareno
  • 576
  • 8
  • 10