Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   cunfused why gevent block redis' socket request? (http://www.velocityreviews.com/forums/t955926-cunfused-why-gevent-block-redis-socket-request.html)

Tony Shao 12-29-2012 03:46 AM

cunfused why gevent block redis' socket request?
 
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!


All times are GMT. The time now is 01:24 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57