#34432: autoreloader does not reload when a Thread is running and there is no
way
to notify the Thread to stop
-----------------------------------------+------------------------
Reporter: David Greaves | Owner: nobody
Type: Bug | Status: new
Component: Utilities | Version: 4.1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-----------------------------------------+------------------------
A running Thread prevents the autoloader from restarting.
Follow page 1 of the tutorial to create a polls app.
Add 'polls.apps.PollsConfig' to INSTALLED_APPS
Use this minimal apps.py in mysite/polls/:
{{{
import logging
import threading
import os
from django.apps import AppConfig
class PollsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'polls'
def ready(self):
logging.warning("In polls.ready")
if os.environ.get("RUN_MAIN") == "true":
logging.warning("Starting Thread")
ev = threading.Event()
self._thread = threading.Thread(target=ev.wait)
self._thread.start()
def stopper(**kwargs): # receiver needs **kwargs
logging.warning("Stopping the Thread")
ev.set()
try:
from django.utils.autoreload import autoreload_stopping
autoreload_stopping.connect(stopper)
except ImportError:
pass
}}}
run python manage.py runserver
make a change to apps.py
Result is that runserver hangs like so:
{{{
Quit the server with CONTROL-C.
/everything/devel/ad-hoc/django/mysite/polls/apps.py changed, reloading.
INFO:django.utils.autoreload:/everything/devel/ad-
hoc/django/mysite/polls/apps.py changed, reloading.
}}}
Apply patch:
https://github.com/django/django/pull/16674/commits/c07a1f35ac7bec04243f10a90df52e9ed0b77d0b
Result is correct reloading:
{{{
Quit the server with CONTROL-C.
/everything/devel/ad-hoc/django/mysite/polls/apps.py changed, reloading.
INFO:django.utils.autoreload:/everything/devel/ad-
hoc/django/mysite/polls/apps.py changed, reloading.
WARNING:root:Stopping the Thread
WARNING:root:In polls.ready
WARNING:root:Starting Thread
Watching for file changes with StatReloader
INFO:django.utils.autoreload:Watching for file changes with StatReloader
}}}
This bug is real and is intended to facilitate discussion of the patch :)
--
Ticket URL: <https://code.djangoproject.com/ticket/34432>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/010701870e61e2da-67bfbd1f-8f65-437b-a1ff-34ee542c304a-000000%40eu-central-1.amazonses.com.