# Ruby 1.91.376 hangs when launched with python pExpect

**URL:** <https://www.ruby-forum.com/t/ruby-1-91-376-hangs-when-launched-with-python-pexpect/187353>\
**Category:** Ruby\
**Created:** [April 22, 2010, 2:57am UTC](https://www.ruby-forum.com/t/ruby-1-91-376-hangs-when-launched-with-python-pexpect/187353 "2010-04-22T02:57:48Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidjrice](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/5e9695/32.png) [@davidjrice](https://www.ruby-forum.com/u/davidjrice)\
**Post date:** [April 22, 2010, 2:57am UTC](https://www.ruby-forum.com/t/ruby-1-91-376-hangs-when-launched-with-python-pexpect/187353/1 "2010-04-22T02:57:48Z")

</div>

Hi

I have a ruby program which has a UI using readline library. In the  
background it launches some ruby threads which serve as a tcp server. It  
works fine so far. But when it is launched on an automated way using  
python pExpect the tcp server threads do not dequeue their packets. But  
if from pExpect I send a message to the UI, the ruby threads move and  
dequeue their packets. The trace of the readline thread and the ones  
which has packets to dequeue is attached. I appreciate if somebody could  
take a look why is this happening?

Thanks,

David

---

<div class="post-metadata">

**Author:** ![davidjrice](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/5e9695/32.png) [@davidjrice](https://www.ruby-forum.com/u/davidjrice)\
**Post date:** [April 22, 2010, 10:02pm UTC](https://www.ruby-forum.com/t/ruby-1-91-376-hangs-when-launched-with-python-pexpect/187353/2 "2010-04-22T22:02:58Z")

</div>

David R. wrote:

> Hi
> 
> I have a ruby program which has a UI using readline library. In the  
> background it launches some ruby threads which serve as a tcp server. It  
> works fine so far. But when it is launched on an automated way using  
> python pExpect the tcp server threads do not dequeue their packets.

Maybe readline is getting confused somehow. You could try using pure  
ruby readline.  
-rp

---

<div class="post-metadata">

**Author:** ![davidjrice](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/5e9695/32.png) [@davidjrice](https://www.ruby-forum.com/u/davidjrice)\
**Post date:** [April 22, 2010, 11:40pm UTC](https://www.ruby-forum.com/t/ruby-1-91-376-hangs-when-launched-with-python-pexpect/187353/3 "2010-04-22T23:40:22Z")

</div>

Hi Roger

I am using ruby Readline as:  
while @logout == false  
cmd =Readline::readline(’\>’,true)  
process\_command(cmd) if !cmd.nil?  
end

adn it works fine when running independently but not when running from  
the pExpect. So I changed to use jsut stdin.gets as:

while @logout == false  
print “\>”  
$stdout.flush  
process\_command($stdin.gets)  
end

and it seems to be working now. But what I saw is that my program has  
between 10 to 40 threads and the ones that have packets to dequeue are  
waiting on  
the \_\_lll\_lock\_wait. So those threads looks like they are out of the  
select but somehow they are stuck in this lock\_wait.

Thanks

David

#0 0x00d32410 in \_\_kernel\_vsyscall()  
#1 0x00b45509 in \_\_lll\_lock\_wait () from lib/libpthread.so.0  
#2 0x00b40bbf in \_L\_lock\_885 () from /lib/libpthread.so.0  
#3 0x00b40a86 in pthread\_mutex\_lock () from /lib/libpthread.so.0  
#4 0x0811daae in native\_mutex\_lock (lock=0xfffffffc) at  
thread\_pthread.c:36  
#5 0x081225d2 in do\_select (n=7, read=0x9856938, write=0x0, except=0x0,  
timeout=0x0) at thread.c:984  
#6 0x0812279c in rb\_thread\_wait\_fd\_rw (fd=6, read=1) at thread.c:2475  
#7 0x00861827 in s\_recvfrom (sock=, argc=, argv=, from=RECV\_IP)

---

<div class="post-metadata">

**Author:** ![davidjrice](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/5e9695/32.png) [@davidjrice](https://www.ruby-forum.com/u/davidjrice)\
**Post date:** [April 23, 2010, 12:41am UTC](https://www.ruby-forum.com/t/ruby-1-91-376-hangs-when-launched-with-python-pexpect/187353/4 "2010-04-23T00:41:24Z")

</div>

Hi Roger

> Hmm. One thing to remember is Ruby has a GLI, which means that if any  
> one thread is _not_ within a rb\_thread\_blocking\_region then it can block  
> your process. With 1.9.x, anyway.

Could you explain me what is a GLI and what does it mean when a thread  
is “in” and is “not” in a rb\_thread\_blocking\_region. And why any thread  
“not” could block my process ? Actually I see in my threads many  
threads “in” a rb\_thread\_blocking\_region doing waitpid which I assume  
for the others thread I launch.

Thanks,

David

---

<div class="post-metadata">

**Author:** ![davidjrice](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/5e9695/32.png) [@davidjrice](https://www.ruby-forum.com/u/davidjrice)\
**Post date:** [April 22, 2010, 11:50pm UTC](https://www.ruby-forum.com/t/ruby-1-91-376-hangs-when-launched-with-python-pexpect/187353/5 "2010-04-22T23:50:09Z")

</div>

> and it seems to be working now. But what I saw is that my program has  
> between 10 to 40 threads and the ones that have packets to dequeue are  
> waiting on  
> the \_\_lll\_lock\_wait. So those threads looks like they are out of the  
> select but somehow they are stuck in this lock\_wait.

Hmm. One thing to remember is Ruby has a GLI, which means that if any  
one thread is _not_ within a rb\_thread\_blocking\_region then it can block  
your process. With 1.9.x, anyway.  
So make sure this isn’t the case. If you’re on Linux it shouldn’t be.  
-rp

---

<div class="post-metadata">

**Author:** ![davidjrice](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/5e9695/32.png) [@davidjrice](https://www.ruby-forum.com/u/davidjrice)\
**Post date:** [April 25, 2010, 7:43am UTC](https://www.ruby-forum.com/t/ruby-1-91-376-hangs-when-launched-with-python-pexpect/187353/6 "2010-04-25T07:43:39Z")

</div>

> Could you explain me what is a GLI and what does it mean when a thread  
> is “in” and is “not” in a rb\_thread\_blocking\_region. And why any thread  
> “not” could block my process ? Actually I see in my threads many  
> threads “in” a rb\_thread\_blocking\_region doing waitpid which I assume  
> for the others thread I launch.

[http://www.igvita.com/2008/11/13/concurrency-is-a-myth-in-ruby](http://www.igvita.com/2008/11/13/concurrency-is-a-myth-in-ruby)

might help.

In general if you have one thread that’s not within a select, it “might”  
be blocking all threads. I don’t know if that’s actually your problem  
here, though.  
-rp

---

<div class="post-metadata">

**Author:** ![davidjrice](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/5e9695/32.png) [@davidjrice](https://www.ruby-forum.com/u/davidjrice)\
**Post date:** [April 25, 2010, 11:12pm UTC](https://www.ruby-forum.com/t/ruby-1-91-376-hangs-when-launched-with-python-pexpect/187353/7 "2010-04-25T23:12:05Z")

</div>

Thanks Roger

Very helpful!
