Created
May 2, 2011 12:58
-
-
Save edsu/951570 to your computer and use it in GitHub Desktop.
simple test of multiprocessing in wsgi environment
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
#!/usr/bin/env python | |
""" | |
install web.py and mod_wsgi and put this in your apache config: | |
WSGIScriptAlias /multiprocessing /home/ed/wsgi_multiprocessing.py | |
AddType text/html .py | |
Then visit, | |
http://localhost/ | |
and compare with: | |
http://localhost/?multiprocessing=1 | |
Interestingly it seems to work just fine in single-threaded mode (without mod_wsgi): | |
./wsgi_multiprocessing.py | |
and visit: | |
http://localhost:8080/?multiprocessing=1 | |
""" | |
import web | |
import multiprocessing | |
urls = ('/', 'index') | |
def x(y): | |
return y | |
class index: | |
def GET(self): | |
q = web.input(multiprocessing=None) | |
if q.multiprocessing: | |
pool = multiprocessing.Pool(processes=1) | |
pool.map(x, [1]) | |
return "Hello Multiprocessing!" | |
else: | |
return "Hello World!" | |
app = web.application(urls, globals()) | |
application = app.wsgifunc() | |
if __name__ == "__main__": | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment