Opened 17 years ago

Closed 15 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: dev
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

Description

Quick way of reproducing:

  1. Start a new project
  2. Replace urls.py 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 manage.py 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 http://127.0.0.1:8080/
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 by Ino Pua <inopua@…>, 17 years ago

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

comment:2 by Ramiro Morales, 17 years ago

Resolution: invalid
Status: newclosed

IMHO this belongs in the django-users mailing list.

comment:3 by Ino Pua <inopua@…>, 17 years ago

Ok, posted it there now.

comment:5 by krzysieksilnia, 15 years ago

Resolution: invalid
Status: closedreopened

Heading

Environment:

Request Method: GET
Request URL: http://IP:8080/stop/
Django Version: 1.0-final-SVN-unknown
Python Version: 2.4.4
Installed Applications:
['django.contrib.auth',

'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'mysite.s1']

Installed Middleware:
('django.middleware.common.CommonMiddleware',

'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware')

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

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

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

  1. cmdname = requestcmd

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

Subheading

comment:6 by Malcolm Tredinnick, 15 years ago

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