Permalink
Browse files

D'oh. The server needs to be in another thread.

  • Loading branch information...
1 parent 0036286 commit db2385c070b1274786bb004cefe36f3431ad8afc @mnot mnot committed Feb 28, 2012
Showing with 19 additions and 17 deletions.
  1. +7 −9 bin/webui.py
  2. +1 −1 test/deploy/Makefile
  3. +11 −7 test/test_webui.py
View
@@ -496,7 +496,7 @@ def response_done(trailers):
except_handler_factory(sys.stdout.write)()
-def standalone_main(port, static_dir, start_cb=None):
+def standalone_main(host, port, static_dir):
"""Run RED as a standalone Web server."""
# load static files
@@ -549,10 +549,8 @@ def request_start(method, uri, req_hdrs):
x.response_start("404", "Not Found", [])
x.response_done([])
- server = thor.HttpServer("", port)
+ server = thor.HttpServer(host, port)
server.on('exchange', red_handler)
- if start_cb:
- server.on('start', start_cb)
try:
thor.run()
@@ -562,11 +560,11 @@ def request_start(method, uri, req_hdrs):
# TODO: logging
# TODO: extra resources
-def standalone_monitor (port, static_dir):
+def standalone_monitor (host, port, static_dir):
"""Fork a process as a standalone Web server and watch it."""
from multiprocessing import Process
while True:
- p = Process(target=standalone_main, args=(port, static_dir))
+ p = Process(target=standalone_main, args=(host, port, static_dir))
sys.stderr.write("* Starting RED server...\n")
p.start()
p.join()
@@ -600,7 +598,7 @@ def standalone_monitor (port, static_dir):
)
# import pdb
-# pdb.run('standalone_main(port, static_dir)')
- standalone_main(port, static_dir)
-# standalone_monitor(port, static_dir)
+# pdb.run('standalone_main("", port, static_dir)')
+ standalone_main("", port, static_dir)
+# standalone_monitor("", port, static_dir)
View
@@ -11,7 +11,7 @@ redbot: clean-redbot
mkdir -p static
cp -Rp $(source)/share/* static/
cp -Rp $(source)/redbot .
- sed -i '/DEBUG_CONTROL/s/False/True/g' webui.py
+ sed -i .old '/DEBUG_CONTROL/s/False/True/g' webui.py
share: clean-share
cd $(source)/share; make
View
@@ -44,14 +44,18 @@ class CnnWebUiTest(BasicWebUiTest):
if redbot_uri:
unittest.main()
else:
+ test_host = "localhost"
test_port = 8080
- redbot_uri = "http://localhost:%s/" % test_port
+ redbot_uri = "http://%s:%s/" % (test_host, test_port)
import sys
sys.path.insert(0, "deploy")
- import webui
- import thor
- def cb():
- unittest.main()
- thor.stop()
- webui.standalone_main(test_port, "deploy/static", cb)
+ def redbot_run():
+ import webui
+ webui.standalone_main(test_host, test_port, "deploy/static")
+ from multiprocessing import Process
+ p = Process(target=redbot_run)
+ p.start()
+ unittest.main(exit=False)
+ print "done test..."
+ p.terminate()

0 comments on commit db2385c

Please sign in to comment.