[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Thread, external processes, and trap

James Mills

9/11/2006 3:54:00 AM

Hello list.

I have what I hope is a simple newbie problem.

I have a ruby program that is acting as a "controller" between a
remote application and an external process. Basically the controller
receives a command from the remote application, does some quick
formatting, then connects to the remote process via an admin interface
and sends the command.

In order to ensure that I have an external process to send information
to, I spawn it and watch it from within the ruby controller. I also
want to keep an eye on it and re-spawn it if needed. So basically I
used Thread.new twice. The first thread is the process "watcher"
which spans the actual process thread. Once it does this, the watcher
thread sleeps until the process thread exits. If the process does
exit for some reason, the watcher thread will respawn it a
configurable number of times.

This actually works pretty good, in and of itself. The problem comes
when I introduce a SIGINT trap in the main body of my code. The INT
trap simply cleans up the running threads and exits. This also works
fine by itself.

The problem is when I try and use ^C to exit the program *after* I've
already respawned the process thread. Here are a few scenarios:

1) watcher and proc threads up and running with no respawns. ^C is
pressed - App exits as expected

2) watcher and proc threads up and running. I kill the external
process manually - The watcher thread catches the fact that the
process thread is no longer running and respawns it

3) watcher and proc threads up and running. I kill the external
process manually, and the watcher respawns it. I press ^C - The
process thread is killed and the watcher catches and respawns it! The
trap code is never executed!!!!


This problem has really frustrated me, and I hope the list can give me
a hand. This is my first app using Threads, so go easy...

Thanks,
~james

2 Answers

Robert Klemme

9/11/2006 5:36:00 AM

0

James Mills wrote:
> In order to ensure that I have an external process to send information
> to, I spawn it and watch it from within the ruby controller. I also
> want to keep an eye on it and re-spawn it if needed. So basically I
> used Thread.new twice. The first thread is the process "watcher"
> which spans the actual process thread. Once it does this, the watcher
> thread sleeps until the process thread exits. If the process does
> exit for some reason, the watcher thread will respawn it a
> configurable number of times.

> 3) watcher and proc threads up and running. I kill the external
> process manually, and the watcher respawns it. I press ^C - The
> process thread is killed and the watcher catches and respawns it! The
> trap code is never executed!!!!

That's probably because a) the trap block is executed in the context of
the watcher thread and b) exit uses an exception to terminate the process:

robert@fussel /cygdrive/c/Temp
$ ruby -e 'begin exit; rescue Exception => e; p e end'
#<SystemExit: exit>

robert@fussel /cygdrive/c/Temp
$ ruby -e 'puts SystemExit.ancestors'
SystemExit
Exception
Object
Kernel

I guess you catch Exception in your watcher and not something more
specific. You should probably either catch more selective or check the
exception and act accordingly in your watcher thread.

Kind regards

robert

alex

11/22/2008 8:16:00 AM

0

it is thw same if I do this


Excel.Application excelApp = new Excel.Application();
excelApp.Visible = true;
excelApp.Application.Workbooks.Add(true);
excelApp.Cells[1, 1] = TextBox1.Text;

"Joel" wrote:

> I think your problem is the filename "/book.xls". The forward slash will go
> to the root directory and look for book.xls. Your file is not on the root
> directory and needs a longer path name.
>
> "Alex" wrote:
>
> > I have a simple c# application
> >
> > Excel.Application excelApp = new Excel.Application();
> > excelApp.Visible = true;
> > string workbookPath = "/book.xls";
> > excelApp.Application.Workbooks.Open(workbookPath,
> > Type.Missing, Type.Missing, Type.Missing, Type.Missing,
> > Type.Missing, Type.Missing, Type.Missing, Type.Missing,
> > Type.Missing, Type.Missing, Type.Missing, Type.Missing,
> > Type.Missing, Type.Missing);
> >
> >
> > excelApp.Cells[1, 1] = TextBox1.Text;
> >
> > When I run it from VS development Server it open Excel file Ok, but when I
> > put it in virtual directory it runs excel.exe process and shows nothing, no
> > errors
> >
> > what can it be?
> > thanks