cunfused why gevent block redis' socket request?

Discussion in 'Python' started by Tony Shao, Dec 29, 2012.

  1. Tony Shao

    Tony Shao Guest

    GOAL:spawn a few greenlet worker deal with the data pop from redis (pop from redis and then put into queue)

    RUNNING ENV: ubuntu 12.04
    PYTHON VER: 2.7
    GEVENT VER: 1.0 RC2
    REDIS VER:2.6.5
    REDIS-PY VER:2.7.1

    from gevent import monkey; monkey.patch_all()
    import gevent
    from gevent.pool import Group
    from gevent.queue import JoinableQueue
    import redis

    tasks = JoinableQueue()
    task_group = Group()

    def crawler():
    while True:
    if not tasks.empty():
    print tasks.get()
    gevent.sleep()

    task_group.spawn(crawler)
    redis_client = redis.Redis()
    data = redis_client.lpop('test') #<----------Block here
    tasks.put(data)


    Try to pop data from redis, but it blocked..and no exception raised...just freeze
    and remove spawn method ,it will worked..
    i feel confuse what happened, plz help!
    thk u!
     
    Tony Shao, Dec 29, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,137
    Smokey Grindel
    Dec 2, 2006
  2. self.python
    Replies:
    4
    Views:
    846
    Damjan
    Jul 7, 2012
  3. subin

    concurrent.futures vs gevent

    subin, Jul 29, 2012, in forum: Python
    Replies:
    0
    Views:
    154
    subin
    Jul 29, 2012
  4. 月忧茗

    gevent + urllib2 blocking

    月忧茗, Feb 22, 2013, in forum: Python
    Replies:
    0
    Views:
    129
    月忧茗
    Feb 22, 2013
  5. Roy Smith

    Weird problem with UDP and gevent

    Roy Smith, Oct 18, 2013, in forum: Python
    Replies:
    3
    Views:
    134
    Grant Edwards
    Oct 19, 2013
Loading...

Share This Page