Opened 12 years ago

Closed 10 years ago

#3712 closed (duplicate)

Starting other processes in a view gives me some weird results.

Reported by: Ino Pua <inopua@…> Owned by: Adrian Holovaty
Component: Core (Other) Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Quick way of reproducing:

  1. Start a new project
  2. Replace with:
from django.conf.urls.defaults import *
from django.http import HttpResponse
import subprocess

def start(request):
    cmdname = request['cmd']
    p = subprocess.Popen([cmdname, 'start'], stdout=subprocess.PIPE)
    stdout, stderr = p.communicate()
    return HttpResponse(stdout or stderr)

def stop(request):
    cmdname = request['cmd']
    p = subprocess.Popen([cmdname, 'stop'], stdout=subprocess.PIPE)
    stdout, stderr = p.communicate()
    return HttpResponse(stdout or stderr)

urlpatterns = patterns('',
    (r'start/$', start),
    (r'stop/$', stop),
  1. Start the django server (python runserver 8080)
  2. Access an url like: http://localhost:8080/start/?cmd=/etc/init.d/exim4, or any cmd= that starts a service (anything that daemonizes). You'll notice that the loading bar (in my firefox at least) never stops loading, even though the django web server is done with the request, and the page has been rendered.
  3. If you now stop the server and try to start it again, it wont be able to bind to its port:
Validating models...
0 errors found.

Django version 0.96-pre, using settings 'starter.settings'
Development server is running at
Quit the server with CONTROL-C.
Error: (48, 'Address already in use')

However, at this time, Im not sure whats causing this to happen. Any ideas would be appreciated.

Shutting the started service down manually, or accessing the /stop/?cmd= url before stopping the django server fixes the problem.

Change History (6)

comment:1 Changed 12 years ago by Ino Pua <inopua@…>

Remember to start the server (python runserver) as root if you're using /etc/init.d-scripts to start and stop daemons ;)

comment:2 Changed 12 years ago by Ramiro Morales

Resolution: invalid
Status: newclosed

IMHO this belongs in the django-users mailing list.

comment:3 Changed 12 years ago by Ino Pua <inopua@…>

Ok, posted it there now.

comment:4 Changed 11 years ago by John Shaffer <jshaffer2112@…>

comment:5 Changed 10 years ago by krzysieksilnia

Resolution: invalid
Status: closedreopened



Request Method: GET
Request URL: http://IP:8080/stop/
Django Version: 1.0-final-SVN-unknown
Python Version: 2.4.4
Installed Applications:


Installed Middleware:


File "/usr/lib/python2.4/site-packages/django/core/handlers/" in get_response

  1. response = callback(request, *callback_args, callback_kwargs)

File "/home/user/Django-1.0/django/bin/mysite/../mysite/" in stop

  1. cmdname = requestcmd?

Exception Type: TypeError at /stop/
Exception Value: unsubscriptable object


comment:6 Changed 10 years ago by Malcolm Tredinnick

Resolution: duplicate
Status: reopenedclosed

Appears to be a duplicate of #9286 and since that's already open, I'm reclosing this one (the other ticket has more information available). If you have new information to help diagnosing #9286, please add it there (but use the "preview" button first and fix the formatting, since your comment here is unreadable). If you are just indicating that you also see the problem, there's not much point adding a comment, since we already know the issue exists.

Note: See TracTickets for help on using tickets.
Back to Top