Created
March 6, 2016 01:39
-
-
Save pior/a494e75efa1ee45a4033 to your computer and use it in GitHub Desktop.
Using a multiprocessing.pool.ThreadPool wih uWSGI -- Tested with gevent
This file contains hidden or 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
| from gevent.monkey import patch_all | |
| patch_all() | |
| import time | |
| from multiprocessing.pool import ThreadPool | |
| import uwsgi | |
| emitter = ThreadPool(10) | |
| def goodbye(): | |
| print " ---- Shutdown worker %d" % uwsgi.worker_id() | |
| emitter.close() | |
| print " ---- Waiting emitter to close" | |
| emitter.join() | |
| print " ---- Emitter closed" | |
| uwsgi.atexit = goodbye | |
| def long_task(): | |
| print " -- IN" | |
| time.sleep(5) | |
| print " -- OUT" | |
| def application(env, start_response): | |
| emitter.apply_async(long_task) | |
| start_response('200 OK', [('Content-Type', 'text/html')]) | |
| return [b"Hello World"] | |
| # uwsgi --http :9090 --wsgi-file app.py --master-fifo uwsgi-fifo --enable-threads --lazy-apps --gevent 10 | |
| # Graceful shutdown : | |
| # echo q > uwsgi-fifo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you know why the
lazy-appsoption is needed?