[#13775] Problems with racc rule definitions — Michael Neumann <neumann@...>

15 messages 2001/04/17
[#13795] Re: Problems with racc rule definitions — Minero Aoki <aamine@...> 2001/04/18

Hi,

[#13940] From Guido, with love... — Dave Thomas <Dave@...>

52 messages 2001/04/20

[#13953] regexp — James Ponder <james@...>

Hi, I'm new to ruby and am coming from a perl background - therefore I

19 messages 2001/04/21

[#14033] Distributed Ruby and heterogeneous networks — harryo@... (Harry Ohlsen)

I wrote my first small distributed application yesterday and it worked

15 messages 2001/04/22

[#14040] RCR: getClassFromString method — ptkwt@...1.aracnet.com (Phil Tomson)

It would be nice to have a function that returns a class type given a

20 messages 2001/04/22

[#14130] Re: Ruby mascot proposal — "Conrad Schneiker" <schneik@...>

Guy N. Hurst wrote:

21 messages 2001/04/24
[#14148] Re: Ruby mascot proposal — Stephen White <spwhite@...> 2001/04/24

On Tue, 24 Apr 2001, Conrad Schneiker wrote:

[#14188] Re: Ruby mascot proposal — matz@... (Yukihiro Matsumoto) 2001/04/25

Hi,

[#14193] Re: Ruby mascot proposal — "W. Kent Starr" <elderburn@...> 2001/04/25

On Tuesday 24 April 2001 23:02, Yukihiro Matsumoto wrote:

[#14138] Re: python on the smalltalk VM — Conrad Schneiker <schneik@...>

FYI: Thought this might be of interest to the JRuby and Ruby/GUI folks.

27 messages 2001/04/24
[#14153] Re: python on the smalltalk VM — Andrew Kuchling <akuchlin@...> 2001/04/24

Conrad Schneiker <schneik@austin.ibm.com> writes:

[#14154] array#flatten! question — Jim Freeze <jim@...> 2001/04/24

Hello.

[#14159] Can I insert into an array — Jim Freeze <jim@...> 2001/04/24

Ok, this may be a dumb question, but, is it possible to insert into an

[#14162] Re: Can I insert into an array — Dave Thomas <Dave@...> 2001/04/24

Jim Freeze <jim@freeze.org> writes:

[#14289] RCR: Array#insert — Shugo Maeda <shugo@...> 2001/04/27

At Wed, 25 Apr 2001 01:28:36 +0900,

[#14221] An or in an if. — Tim Pettman <tjp@...>

Hi there,

18 messages 2001/04/25

[#14267] Re: Ruby mascot proposal — "Conrad Schneiker" <schneik@...>

Danny van Bruggen,

16 messages 2001/04/26

[#14452] How to do it the Ruby-way 3 — Stefan Matthias Aust <sma@3plus4.de>

First a question: Why is

21 messages 2001/04/30

[ruby-talk:13931] PTY question [long]

From: "Henry T. So Jr." <henryso@...>
Date: 2001-04-20 15:23:21 UTC
List: ruby-talk #13931
I'm trying to use the PTY extension to run ssh to communicate with a program 
on a foreign host.

I tried using the block form:

begin
  PTY.spawn("ssh ...") { |r,w,p| ... }
rescue RuntimeError
  # the ssh died unexpectedly
end

If I do this, and ssh does not die unexpectedly within the block, I can only 
run this 16 times, after which I get an error from the PTY extension that too 
many ptys are open.

I traced this to the fact that, if the block form is used, the signal handler 
is reset after yielding, and the chld_changed signal handler is never called 
to clean up the child_pid table.  I believe this is a bug, but I don't have 
time at the moment to try and fix it.  (I'm using the PTY extension that comes 
with ruby-1.6.3)

Of course, if ssh dies within the block, the signal handler is called, the 
child_pid table is cleaned up, and the exception is raised.  This allows me to 
run the code above more than 16 times.

So, I converted to use the non-block form:

begin
  r,w,p = PTY.spawn("ssh ...")
  ...
  sleep 5 # wait for the process to die
rescue RuntimeError
  # ignore it because the ssh died
end

Doing it this way allows me to run this more than sixteen times.

The problem is, if something odd happens, I just want to close the connection 
and continue on.  Therefore the code became something like this:

p = nil
begin
  begin
    r,w,p = PTY.spawn("ssh ...")
    ...
    <if there's a problem, raise MyError>
    ...
  rescue MyError
    ...
  ensure
    if p
      sleep 5 # wait for it to die by itself
      Process.kill('KILL', p)
      sleep 5 # wait for the kill to take effect
    end
  end
rescue RuntimeError
  # ignore it because ssh died
end

Before anyone asks, I tried Process.waitpid(p) instead of the second "sleep 
5", but when I did that, the signal handler never gets called to clean up the 
child table and I have the 16 run problem again (except this time, it's 16 
runs where MyError gets raised).

Anyhow, is there any better way of doing this?  The sleep thing seems like 
something of a kludge to get this to work.

On the other hand, the SIGKILL should always succeed (kill -9) so maybe I'm 
just being overly worried.  If this is the case, does anyone think 5 seconds 
for the second "sleep 5" is not enough?  I want to be sure that I catch the 
RuntimeError raised by the chld_changed signal handler in this section of the 
code so as not to disrupt the rest of my program.

Any help or advice would be appreciated.

Thanks,
Henry.

In This Thread

Prev Next