Re: [gevent] How to spawn for a different function after the first one finishes using gevent?

27 views
Skip to first unread message

Matt Billenstein

unread,
Jul 21, 2012, 8:02:15 PM7/21/12
to gev...@googlegroups.com
Not entirely in gevent, but I'd typically do this with an external queue of
some sort (redis or other) and some worker processes which consume jobs from
that queue -- your view function would put work into the queue in that case.
This is doubly good if the heavy work you're doing is at all cpu-bound.

m

On Sat, Jul 21, 2012 at 01:57:56PM -0700, dsfdf wrote:
> I posted on stackoverflow. But no one can answer so let me try here:
> http://stackoverflow.com/questions/11594358/how-to-spawn-for-a-different-function-after-the-first-one-finishes-using-gevent
>
> The basic idea is as follows:
>
> a request comes to views1 and it first returns the username.
> There is some heavy job separate done by do_something_else right
> after views1 is done. You can think of this as creating a new
> user, but has to do some heavy checking on the background.
>
> def views1(..):
> username = get_uername(...)
> return username
> This is a
> favorite from lib import do_something_else
> question def do_something_else(...):
> (click // do heavy stuff here
> again to
> undo) gevent.joinall([
> gevent.spawn(views1, parmeter1, parmeter2, ...),
> gevent.spawn(do_something_else, parmeter1, parmeter2, ...)
> ])
>
> The problem is I don't think do_something_else was ever called
> based on my logging. I read tutorial and I don't know where to
> place gevent.sleep(0). I don't want blocking. I want the user
> sees the username right away, and let do_something_else runs in
> the background.
>
> Any idea?

--
Matt Billenstein
ma...@vazor.com
http://www.vazor.com/

dsfdf

unread,
Jul 21, 2012, 9:03:21 PM7/21/12
to gev...@googlegroups.com, Matt Billenstein
I probably don't understand what all of these queues and corotuines are really doing.

Say I use Celery. I can probbaly do `heavy_function.delay()`

@task
def heavy_function(..):
   // do something heavy
   return something

def view1(...):
    username = ....
    do_heavy_fuynction.delay()  # sednt o Celery Queue
    return username

So what exactly is gevent compare to celery and gunicorn? How do I utilize all three of them?? Sorry for the noob question. Thanks!
Reply all
Reply to author
Forward
0 new messages