Skip to content

Instantly share code, notes, and snippets.

@chadselph
Created February 24, 2012 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chadselph/1902216 to your computer and use it in GitHub Desktop.
Save chadselph/1902216 to your computer and use it in GitHub Desktop.
simpler solution
import threading
from wsgiref.simple_server import make_server
from mylongtask import progress_status, run_task
# simple wsgi app; could replace with one from flask with templates,
# url dispatching, etc.
def simple_app(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/plain')])
return [str(progress_status)]
class TaskThread(threading.Thread):
def run(self):
# instead of just running the task, you could pull tasks
# off using the stdlib Queue module, and add a Flask
# endpoint for adding tasks onto the Queue. Fancy.
run_task()
class WebThread(threading.Thread):
def run(self):
httpd = make_server('', 8000, simple_app)
print "Serving on port 8000..."
httpd.serve_forever()
w = WebThread()
t = TaskThread()
w.start()
t.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment