this starts up two servers - HTTP serving the django application on port 8000 and a port 8001 server that will start an interactive interpreter with any incoming connections. this enables you to have an interpreter in the same process as your server.
$ wget http://localhost:8000/someurl/
(...)
$ nc localhost 8001
Python 2.5.2 (r252:60911, Jul 8 2008, 21:21:10)
[GCC 4.3.1 20080626 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.db import connection
>>> connection.queries
[ ... ]
1 2 3 4 5 6 7 8 9 10 11 12 | #!/usr/bin/env python
import os
from django.core.handlers.wsgi import WSGIHandler
from eventlet import api, backdoor, wsgi
os.environ["DJANGO_SETTINGS_MODULE"] = "settings"
api.spawn(api.tcp_server, api.tcp_listener(("127.0.0.1", 8001)), backdoor.backdoor)
wsgi.server(api.tcp_listener(("127.0.0.1", 8000)), WSGIHandler())
|
More like this
- FileField having auto upload_to path by junaidmgithub 2 days, 1 hour ago
- LazyPrimaryKeyRelatedField by LLyaudet 1 week, 2 days ago
- CacheInDictManager by LLyaudet 1 week, 2 days ago
- MYSQL Full Text Expression by Bidaya0 1 week, 3 days ago
- Custom model manager chaining (Python 3 re-write) by Spotted1270 2 weeks, 2 days ago
Comments
This is ridiculously cool, but is there an advantage to doing it like this over just using "./manage.py shell"? Django servers don't really have any global state, so I'm not sure how useful it is being able to operate in the same process as the server itself.
#
Please login first before commenting.