redis-py subscribe blocked when read message
Recentlly i use python and redis to build a smarl messge-driven project. i
use one thread to subsribe to redis channel(called message thread here); a
timer thread; and a worker thread; when message thread got enough
messages, it post a task to worker. i use redis-py to communicate with
redis
Message Thread: subscribe to redis; while True: get message; if
len(messages)>threashold: post task to Worker
Worker Thread: wait task event; do task; //this may be heavy end;
here comes the problem: after this work for a while, the redis-py subpub
blocked!(ofcource redis is still publish message, but it do not return
anymore, it just blocked!). i use gdb attach to it, i see stack frame like
this:
[Switching to thread 4 (Thread 1084229984 (LWP 9812))]#0
0x000000302b80b0cf in __read_nocancel () from /lib64/tls/libpthread.so.0
(gdb) bt 0 0x000000302b80b0cf in __read_nocancel () from
/lib64/tls/libpthread.so.0
1 0x00000000004e129a in posix_read (self=Variable "self" is not
available.) at./Modules/posixmodule.c:6592
2 0x00000000004a04c5 in PyEval_EvalFrameEx (f=0x157a8c0,
throwflag=Variable "throwflag" is not available.) at Python/ceval.c:4323
i even use redis 'client kill' command to kill the connection between
python and redis, but python still block there, never return or raise
exeption. the only way is to kill the python process use kill -9.
then i comment work's 'do task' procedure(remember this task is heavy, it
make heavy network io, cpu calculation), it works well and no problem
abserved.
so, it seems come to conclusion: Once i use worker do task, message thread
will block at socket read.
How can this happen!!
No comments:
Post a Comment