-
-
Save ikatson/7a290f4e1357fb388f07 to your computer and use it in GitHub Desktop.
Weird behaviour when using gevent+uwsgi+gevent.subprocess
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
[uwsgi] | |
master=true | |
gevent=1000 | |
wsgi=wsgi | |
http=127.0.0.1:9000 |
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 gevent.monkey | |
gevent.monkey.patch_all() | |
import threading | |
import time | |
from gevent import subprocess | |
def start_long_background_subprocess_in_thread(): | |
def start(): | |
# This works! You can try it by uncommenting. | |
# time.sleep(1) | |
# But this does not! | |
subprocess.Popen(['sleep', '5']) | |
# Even this works! But only when time.sleep finishes AFTER the request | |
# was responded. | |
# time.sleep(1) | |
# subprocess.Popen(['sleep', '5']) | |
threading.Thread(target=start).start() | |
def application(environ, start_response): | |
# The request is not completely finished, | |
# until the subprocess is over. Though uWSGI even writes the logline | |
# that the request was finished quickly, and was not waiting for anything. | |
# Example: | |
# GET / => generated 2 bytes in 2 msecs | |
start_long_background_subprocess_in_thread() | |
start_response('200 OK', [('Content-Type', 'text/plain')]) | |
return ['ok'] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment