restarting a django development server

4,190 views
Skip to first unread message

dummyman dummyman

unread,
Apr 23, 2012, 6:10:46 AM4/23/12
to django...@googlegroups.com
how to restart a django development server programmatically in python ?

Joel Goldstick

unread,
Apr 23, 2012, 9:16:57 AM4/23/12
to django...@googlegroups.com
On Mon, Apr 23, 2012 at 6:10 AM, dummyman dummyman <temp...@gmail.com> wrote:
> how to restart a django development server programmatically in python ?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.

python manage.py runserver

--
Joel Goldstick

Joel Goldstick

unread,
Apr 23, 2012, 9:24:49 AM4/23/12
to django...@googlegroups.com
oops I spoke too soon. Didn't see you want to do this
programatically. But I suppose you could just invoke that line using
subprocess? http://docs.python.org/library/subprocess.html#module-subprocess
> --
> Joel Goldstick

--
Joel Goldstick

dummyman dummyman

unread,
Apr 23, 2012, 11:05:16 AM4/23/12
to django...@googlegroups.com
hi

but how do i do it when the server is running ??
i basically want to stop it and restart it in the program
is it possible ?

On Mon, Apr 23, 2012 at 6:54 PM, Joel Goldstick <joel.go...@gmail.com> wrote:
On Mon, Apr 23, 20ogr12 at 9:16 AM, Joel Goldstick

dummyman dummyman

unread,
Apr 23, 2012, 11:38:43 AM4/23/12
to django...@googlegroups.com
basically i ve a form in a class CollFormAdmin where i am overriding two fields to MultipleChoiceField where values are changed dynamically based on a pickle file value
then in CollAdmin class


class CollAdmin(admin.ModelAdmin):

   form=CollFormAdmin

but i want to change the value of MultipleChoiceField dynamically. But it appears like the class is loaded only once and the form is taking the previous old value ie d first one. Thats y i asked a way to restart the server in the code

please help me

Bill Freeman

unread,
Apr 23, 2012, 12:09:02 PM4/23/12
to django...@googlegroups.com
You can "touch" one of the .py files. That is, cause its last modified
date to become newer than that of its .pyc file by making it the current
time.

I suspect that you can do this (assuming that you don't want to run the
*nix "touch" command as a sub process, or don't have it because you
are on an OS that doesn't have it) by opening the file for writing, not
writing to it, and closing it again. But note that I haven't tested this on
any platform, let alone yours.

The development server is actually two processes: the one you start
with manage, and the one actually running Django, which is started by
the first "driver" process. The driver process then spends its time
watching for files to change, and when it sees one do so, it restarts
the server process. However you can manage to implement touch on
your platform.

Note that this is specific to the development server. But note that mod_wsgi
has a similar watch upon just the .wsgi file (which doesn't have to be
named with .wsgi, it's just the one that the WSGIScripAlias points to).

dummyman dummyman

unread,
Apr 23, 2012, 12:22:10 PM4/23/12
to django...@googlegroups.com
awesome man :) it worked 

Andy McKay

unread,
Apr 23, 2012, 3:52:45 PM4/23/12
to django...@googlegroups.com
Change your code so you don't have to. Relying on a restart for that
is the wrong approach.

dummyman dummyman

unread,
Apr 24, 2012, 3:36:30 AM4/24/12
to django...@googlegroups.com
wat is the workaround for creating a form each time when he enters d add form ?

On Tue, Apr 24, 2012 at 1:22 AM, Andy McKay <an...@clearwind.ca> wrote:
Change your code so you don't have to. Relying on a restart for that
is the wrong approach.
Reply all
Reply to author
Forward
0 new messages