Thank you, dear Sir! I have tried as-user-atexit and it does not work with Ctrl+c event. Don't know about other exit events since my machine powers the light in question. So the light goes off when machine goes off anyway.
Maybe if I constantly check fo existance of some django system process? On Saturday, September 10, 2016 at 5:27:21 PM UTC+2, Michal Petrucha wrote: > > On Sat, Sep 10, 2016 at 01:51:00AM -0700, Krešimir wrote: > > Hello, > > > > I have a turn_the_light_on() function that, well, turns on a light... > > I put it in wsgi.py (as suggested by internet) just before application = > > get_wsgi_application()call. > > > > Where can I put turn_the_light_off() function call to turn off the light > > when the application quits? > > > > Thank you! > > In short, there is no such thing. In the most common scenario > (including yours, based on your email), Django is used as a WSGI > application, which starts up once, and then lives inside an > application server, which listens to requests, and translates them > into function calls. In that sense, Django is more of a passive thing, > that waits to be called with a request, which it then dutifully > processes, and finally enters the waiting state again. This happens > until the application server itself exits, but that is out of the > scope of what Django does. > > Usually, application servers also just run indefinitely, until they > are killed. Or you can configure them to only run for a certain amount > of time. Or you can set them up to quit and restart after they process > a certain number of requests. Either way, the shutdown sequence > usually consists of just terminating the process. > > What you are asking for sounds like it falls into the responsibility > of your application server. For example, Gunicorn has an ``on_exit`` > hook [1], or if you're using uwsgi, it also has some hooks [2], though > I haven't been able to extract much useful information at a glance, > but you might be able to find something that suits your need. > > Cheers, > > Michal > > > [1]: http://docs.gunicorn.org/en/latest/settings.html#on-exit > [2]: https://uwsgi-docs.readthedocs.io/en/latest/Hooks.html > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/193f95a3-70f5-4561-b459-8eb0a4a209d5%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.

