Starting other processes in a view gives me some weird results.
|Reported by:||Ino Pua <inopua@…>||Owned by:||adrian|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Quick way of reproducing:
- Start a new project
- 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), )
- Start the django server (python manage.py runserver 8080)
- 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.
- 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 Changed 8 years ago by Ino Pua <inopua@…>
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
comment:2 Changed 8 years ago by Ramiro Morales
- Resolution set to invalid
- Status changed from new to closed
comment:5 Changed 6 years ago by krzysieksilnia
- Resolution invalid deleted
- Status changed from closed to reopened