Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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.
class WebThread(threading.Thread):
def run(self):
httpd = make_server('', 8000, simple_app)
print "Serving on port 8000..."
w = WebThread()
t = TaskThread()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment