Skip to content

Instantly share code, notes, and snippets.

@ikatson
Created October 23, 2013 17:37
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 ikatson/7a290f4e1357fb388f07 to your computer and use it in GitHub Desktop.
Save ikatson/7a290f4e1357fb388f07 to your computer and use it in GitHub Desktop.
Weird behaviour when using gevent+uwsgi+gevent.subprocess
[uwsgi]
master=true
gevent=1000
wsgi=wsgi
http=127.0.0.1:9000
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