public
Created

simpler solution

  • Download Gist
webui.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
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()

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.