Created
February 24, 2012 17:26
-
-
Save chadselph/1902216 to your computer and use it in GitHub Desktop.
simpler solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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