Note that there are some explanatory texts on larger screens.

plurals
  1. POredis-py subscribe blocked when read message
    text
    copied!<p>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 <strong>redis-py</strong> to communicate with redis</p> <p>Message Thread:</p> <p>subscribe to redis;</p> <pre><code>while True: get message; if len(messages)&gt;threashold: post task to Worker </code></pre> <p>Worker Thread:</p> <pre><code>while True: wait task event; do task; //this may be heavy </code></pre> <p>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:</p> <p>[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</p> <p>1 0x00000000004e129a in posix_read (self=Variable "self" is not available.) at./Modules/posixmodule.c:6592</p> <p>2 0x00000000004a04c5 in PyEval_EvalFrameEx (f=0x157a8c0, throwflag=Variable "throwflag" is not available.) at Python/ceval.c:4323</p> <p>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.</p> <p>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.</p> <p>so, it seems come to conclusion: Once i use worker do task, message thread will block at socket read.</p> <p>How can this happen!!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload