[uWSGI] yield in async mode

Roberto De Ioris roberto at unbit.it
Fri Dec 23 09:23:28 CET 2011

> In async mode, my code is like below:
> def application(environ, start_response):
>     ......
>     if cmd == "search":
>           search_func(...)
>     elif
>         ......
> def search_func(......):
>       ......
>       uwsgi.wait_fd_read(......)
>       yield
>       ......
>      yield
> But the performance drops dramatically. I think it's because the nested
> 'yield'.

For deep functions you should use some form of coroutine (ugreen,
greenlet, stackless..)

uGreen is compiled in by default, simply enable it with --ugreen and
change your app logic to be "suspended" whenever you need it with

By the way your current logic is broken as search_func() will block til
the whole output is available.

You should do

for chunk is search_func(...):
    yield chunk

Roberto De Ioris

More information about the uWSGI mailing list