Login

server with debugging backdoor

Author:
teepark
Posted:
September 8, 2008
Language:
Python
Version:
1.0
Score:
6 (after 6 ratings)

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

  1. Template tag - list punctuation for a list of items by shapiromatron 11 months, 2 weeks ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 11 months, 3 weeks ago
  3. Serializer factory with Django Rest Framework by julio 1 year, 6 months ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 7 months ago
  5. Help text hyperlinks by sa2812 1 year, 7 months ago

Comments

simon (on September 8, 2008):

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.