[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Non-Threaded Timeout?

Bryan Richardson

8/8/2008 1:59:00 PM

Hell all,

I'm looking for a way to implement a non-threaded timeout. I am running
some Monte Carlo simulations using an external application via an OLE
interface. There are times where the external application seems to hang
up, so I'm looking for a way to detect this and continue on with my
simulation if the external application takes too long.

Any suggestions?

--
Thanks!
Bryan
--
Posted via http://www.ruby-....

29 Answers

hemant

8/8/2008 2:16:00 PM

0

On Fri, Aug 8, 2008 at 7:28 PM, Bryan Richardson <btrichardson@gmail.com> wrote:
> Hell all,
>
> I'm looking for a way to implement a non-threaded timeout. I am running
> some Monte Carlo simulations using an external application via an OLE
> interface. There are times where the external application seems to hang
> up, so I'm looking for a way to detect this and continue on with my
> simulation if the external application takes too long.
>

http://ph7spot.com/articles/sy...

Bryan Richardson

8/8/2008 2:36:00 PM

0

Hello Hemant,

Thanks for responding. I am running my application on Windows (the
external app I'm interfacing with is Windows-only), so I'm not sure if
this will help me out... unless it can be configured to not use threads.
I haven't tried timeout.rb because I'm under the impression (from
documentation) that it uses threads and I can't use threads in the Monte
Carlo simulation.

--
Thanks!
Bryan

Hemant Kumar wrote:
> http://ph7spot.com/articles/sy...

--
Posted via http://www.ruby-....

Joel VanderWerf

8/8/2008 5:09:00 PM

0

Bryan Richardson wrote:
> Hello Hemant,
>
> Thanks for responding. I am running my application on Windows (the
> external app I'm interfacing with is Windows-only), so I'm not sure if
> this will help me out... unless it can be configured to not use threads.
> I haven't tried timeout.rb because I'm under the impression (from
> documentation) that it uses threads and I can't use threads in the Monte
> Carlo simulation.

Why can't you use threads to drive your Monte Carlo simulation?

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

Bryan Richardson

8/8/2008 5:18:00 PM

0

Hi Joel,

Well, for one thing, I'm short on time and haven't designed it to work
that way. :) Also, the Ruby interface I've developed for accessing the
external application via the OLE interface has been designed as a
Singleton and I don't know how well that would work with threads...
without a lot of work synchronizing things and such.

--
Thanks!
Bryan

Joel VanderWerf wrote:
> Why can't you use threads to drive your Monte Carlo simulation?

--
Posted via http://www.ruby-....

Adam Shelly

8/8/2008 6:02:00 PM

0

On 8/8/08, Bryan Richardson <btrichardson@gmail.com> wrote:
>>> I'm looking for a way to implement a non-threaded timeout

> Also, the Ruby interface I've developed for accessing the
> external application via the OLE interface has been designed as a
> Singleton and I don't know how well that would work with threads...
> without a lot of work synchronizing things and such.
>

I'm probably very confused, but isn't the the OLE interface
asynchronous already?
Aren't you already waiting until it is done?

The following example runs excel until I close it from the menu, or 30
seconds, whichever comes first. I'd think you could apply the same
thing to your app, especially if your simulation closes itself.

-Adam
-------------------------------------------------------------------------------------
excel = WIN32OLE.new("excel.application")
excel['Visible'] = TRUE;
t = Time.now
while ((Time.now - t) < IT_SHOULD_NEVER_RUN_THIS_LONG)
break if !excel.Visible #using Visible to check if it is running
#there is probably a better test.
sleep(1)
end
excel.Quit();

Bryan Richardson

8/8/2008 6:20:00 PM

0

Hi Adam,

Well, now I think I'm confused too! :)

I do not believe the OLE interface is asynchronous, as I do wait for
results from it before moving on. Therefore, yes I am waiting until it
is done. However, if the program on the other end of the OLE connection
hangs, I'd like to move on by killing the interface and starting a new
one.

The code you suggested seems like a good way to go, however I don't know
what I would test to see if it's still responding. I'll look into that.

--
Thanks!
Bryan

Adam Shelly wrote:
> I'm probably very confused, but isn't the the OLE interface
> asynchronous already?
> Aren't you already waiting until it is done?
>
> The following example runs excel until I close it from the menu, or 30
> seconds, whichever comes first. I'd think you could apply the same
> thing to your app, especially if your simulation closes itself.
>
> -Adam
> -------------------------------------------------------------------------------------
> excel = WIN32OLE.new("excel.application")
> excel['Visible'] = TRUE;
> t = Time.now
> while ((Time.now - t) < IT_SHOULD_NEVER_RUN_THIS_LONG)
> break if !excel.Visible #using Visible to check if it is running
> #there is probably a better test.
> sleep(1)
> end
> excel.Quit();

--
Posted via http://www.ruby-....

Adam Shelly

8/8/2008 7:14:00 PM

0

On 8/8/08, Bryan Richardson <btrichardson@gmail.com> wrote:
> I do not believe the OLE interface is asynchronous, as I do wait for
> results from it before moving on. Therefore, yes I am waiting until it
> is done.
> The code you suggested seems like a good way to go, however I don't know
> what I would test to see if it's still responding.

How exactly do you wait for results? Do you test some property?
Can't you use that test as your loop sentinel?
`break if !monty.Results.empty?` or something like that...

Bryan Richardson

8/8/2008 7:37:00 PM

0

hi adam,

i don't test a property because the ole interface is not asynchronous.
my code looks like this -

do stuff...
result = @sim.RunScriptCommand('SolvePrimalLP()')
do stuff...

when the ole application hangs i never get to the second 'do stuff...'

--
bryan

Adam Shelly wrote:
> How exactly do you wait for results? Do you test some property?
> Can't you use that test as your loop sentinel?
> `break if !monty.Results.empty?` or something like that...

--
Posted via http://www.ruby-....

Bryan Richardson

8/8/2008 7:49:00 PM

0

what about starting another thread to monitor my results variable... i
still don't fully understand the scope of variables when a thread is
started.

--
bryan

Bryan Richardson wrote:
> hi adam,
>
> i don't test a property because the ole interface is not asynchronous.
> my code looks like this -
>
> do stuff...
> result = @sim.RunScriptCommand('SolvePrimalLP()')
> do stuff...
>
> when the ole application hangs i never get to the second 'do stuff...'
>
> --
> bryan
>
> Adam Shelly wrote:
>> How exactly do you wait for results? Do you test some property?
>> Can't you use that test as your loop sentinel?
>> `break if !monty.Results.empty?` or something like that...

--
Posted via http://www.ruby-....

Joel VanderWerf

8/8/2008 8:43:00 PM

0

Bryan Richardson wrote:
> hi adam,
>
> i don't test a property because the ole interface is not asynchronous.
> my code looks like this -
>
> do stuff...
> result = @sim.RunScriptCommand('SolvePrimalLP()')
> do stuff...
>
> when the ole application hangs i never get to the second 'do stuff...'

I don't know much about ole... is RunScriptCommand blocking on a tcp
socket call? If so, it should be possible to wrap a timeout block around
RunScriptCommand. The timeout block starts another thread. If the
timeout fires, the blocked call will be interrupted (ruby's thread
scheduler works well if threads are blocked on socket ops, but not
arbitrary C functions). You can rescue and clean up the socket.

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407