Login

server with debugging backdoor

Author:
teepark
Posted:
September 8, 2008
Language:
Python
Version:
1.0
Tags:
debugging
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. caching parsed templates by forgems 7 years, 8 months ago
  2. YUI Loader as Django middleware by akaihola 7 years, 4 months ago
  3. One line SMTP sink server by Baguage 1 year, 1 month ago
  4. SOAP views with on-demand WSDL generation by chewie 7 years ago
  5. QRCode template tag by bradbeattie 2 years, 9 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.