Permalink
Browse files

moved demo wsgi app to framework_wsgi.py

git-svn-id: http://evserver.googlecode.com/svn/trunk@78 e9bb6d7e-af12-11dd-bad7-87afd3b02348
  • Loading branch information...
1 parent 349574f commit 7b3f15f7a22bd14983f5d68ec50329dd18f0595d majek04 committed Feb 5, 2009
Showing with 24 additions and 21 deletions.
  1. +18 −0 evserver/examples/framework_wsgi.py
  2. +6 −21 evserver/main.py
@@ -0,0 +1,18 @@
+#
+# evserver --exec "import examples.framework_wsgi; application = examples.framework_wsgi.application"
+# or just:
+# evserver --framework=demo
+import datetime
+import socket
+
+
+def application(environ, start_response):
+ start_response("200 OK", [('Content-type','text/plain')])
+ sd = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+ try:
+ while True:
+ yield environ['x-wsgiorg.fdevent.readable'](sd, 1.0)
+ yield "%s\n" % (datetime.datetime.now(),)
+ except GeneratorExit:
+ pass
+ sd.close()
View
@@ -18,6 +18,7 @@
import datetime
import platform
from pkg_resources import resource_filename
+import socket
log = logging.getLogger(os.path.basename(__file__))
@@ -40,30 +41,14 @@ def wsgi_django():
log.info("Running Django. DJANGO_SETTINGS_MODULE=%s, DEBUG=%s" % (os.getenv('DJANGO_SETTINGS_MODULE',''), settings.DEBUG))
return django_wsgi.WSGIHandler()
-def clock_demo(environ, start_response):
- start_response("200 OK", [('Content-type','text/plain')])
- # whatever empty file, we just want to receive a timeout
- fname = '/tmp/fifo'
- try:
- os.mkfifo(fname)
- except OSError:
- pass
- fd = os.open(fname, os.O_RDONLY | os.O_NONBLOCK)
- os.read(fd, 65535)
- try:
- while True:
- yield environ['x-wsgiorg.fdevent.readable'](fd, 1.0)
- yield "%s\n" % (datetime.datetime.now(),)
- except GeneratorExit:
- pass
- os.close(fd)
- return
-
+def demo_app():
+ import examples.framework_wsgi
+ return examples.framework_wsgi.application
-# after called, should return valid ``wsg_application(environ, start_response)`` function
+# after called, should return valid ``wsgi_application(environ, start_response)`` function
FRAMEWORKS = {
'django':wsgi_django,
- 'demo':lambda: clock_demo,
+ 'demo':lambda: demo_app(),
}

0 comments on commit 7b3f15f

Please sign in to comment.