0

Can someone help me gevent's puzzling behavior? Here is my code:
https://gist.github.com/3956734.

I want to know how to use gevent.pool. I spawn one greenlet in one time, the greelet do nothing but sleep for 10 secs. It's supposed to run only for 10 secs, but it runs for 20 secs in realistic situation.

What's wrong with my code? I have read gevent's documentation, but still have no idea.

kuafu
  • 1,466
  • 5
  • 17
  • 28

1 Answers1

1

According to the comment in your code:

#ids_set = {'945453','1909279'}

According to your question, your greenlets do nothing but sleep for 10 seconds.

Assuming both of those things are true then your code...

 while ids_set is not None:
    id = ids_set.pop()
    print 'now id is', id
    pool.spawn(download_content_test,int(id))
    pool.join()

... should run for 20 seconds because you are joining the pool after each spawn. So your code is doing this: spawn, join (10 second wait), spawn, join (10 second wait).

I think what you meant to do was have the pool.join() outside of the while loop. Then it would only wait for 10 seconds.

kkurian
  • 3,844
  • 3
  • 30
  • 49