command for stopping server

1,491 views
Skip to first unread message

Antonín Drdácký

unread,
Sep 7, 2020, 9:37:50 AM9/7/20
to django-d...@googlegroups.com
Hello there,


Basically I would like to run the server and stop it by a program, it is hard, when the default way is literally "pressing ctrl+C",
killing the process is different on different OS'es.
When searching the web (StackOverflow) users replies to individual answers were "This worked for me." or "This didn't work for me.",
this showcases that different conditions make it hard to get to actually stopping the server.

A unified solution would be very nice. If we want to keep "python manage.py runserver" together with "press ctrl+C to quit",
then I would suggest a new command, let's call it "startserver", that would be non-blocking, running subprocess, or something,
once the user is done he simply calls "stopserver" to stop it.
"startserver" vs "runserver" might be similar for some, suggest different command name if you like.

It is only my suggestion, I don't care if it will be more complicated as long as it will "just work" on all OS'es and will be clear to use.

Thanks for your time and consideration
Antonín Drdácký

אורי

unread,
Sep 7, 2020, 10:48:48 AM9/7/20
to Django developers (Contributions to Django itself)
I think the server run by "python manage.py runserver" is just a debugging server, it is not suitable for production. For production you run a web server such as Nginx or Apache which you configure to execute Django.


--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CALALaaN-e-qQ%3DBLuGb4QVAx%2BpEDxWaiRAWFoPnDGoPkNv_Of-w%40mail.gmail.com.

Adam Johnson

unread,
Sep 7, 2020, 12:25:47 PM9/7/20
to django-d...@googlegroups.com
Antonin,

Uri is right that runserver is only suitable for development. It's also worth looking at during development - log output includes system check failures, new migration detection, and stack traces when bugs occur. I normally have it in a terminal window.

If you definitely want to run it in the background during development, it's not a trivial problem, so I don't think Django should build anything. Plenty of mature options already exist:
Hope those help.



--
Adam

Denis Urman

unread,
Sep 7, 2020, 1:39:42 PM9/7/20
to django-d...@googlegroups.com
The canonical way to run a Django server is to link it up to a WSGI (uWSGI) or gunicorn, then run Apache or Nginx on top of that. These latter two things are typically handled through systemd. Some people use Docker or Supervisor, but that might be a lot for you to learn right now. Gunicorn & Nginx is plenty.  

Virus-free. www.avast.com


Virus-free. www.avast.com

Tim Allen

unread,
Sep 8, 2020, 5:48:48 AM9/8/20
to Django developers (Contributions to Django itself)
The advice here is solid, but to answer the initial query... i created a one liner to kill any runservers from my current user, as they can get lost in my sea of terminals. This may help:

alias kill-runserver="ps -eaf | grep 'manage.py runserver' | grep "'$USER'" | grep -v grep | awk '{print "'$2'"}' | xargs kill -9"

Good luck!

Adam Johnson

unread,
Sep 8, 2020, 6:43:11 AM9/8/20
to django-d...@googlegroups.com
A little tip Tim - your one-liner can also be achieved with the pkill utility: pkill -u $USER -f manage.py runserver . The user matching with -u $USER flag is cautious but probably unnecessary.


--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.


--
Adam
Reply all
Reply to author
Forward
0 new messages