Skip to content

Instantly share code, notes, and snippets.

@edsu
Created May 2, 2011 12:58
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 edsu/951570 to your computer and use it in GitHub Desktop.
Save edsu/951570 to your computer and use it in GitHub Desktop.
simple test of multiprocessing in wsgi environment
#!/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