A simpler alternative might be to use something like this adverb:

NB.* doForTime: do verb for set number of seconds.
doForTime=: 1 : 0
   tsEnd=. y+6!:1 ''       NB. Time now + how many seconds to run
   rr=. ''
   while. tsEnd>6!:1 '' do. rr=. u rr end.
)

NB. For example, using an arbitrary function "f"
f=: 3 : '<./y,?100$0'             NB. Find lowest random number

   6!:2 'rr=. f doForTime 5'     NB. Only work on it for 5 seconds.
4.9970432


On 1/15/08, Devon McCormick <[EMAIL PROTECTED]> wrote:
>
> David -
>
> I have a script called "semaphore" which I use to flag a long-running
> process to stop or continue depending on a value in a flag file.  I've put
> it on the J wiki at
> http://www.jsoftware.com/jwiki/DevonMcCormick/semaphore .
>
> The code will need to be customized for your own use but it shouldn't be
> too hard; there are a couple of notes on the page to point out a few items
> to help you do this.  The major problem is that it is probably more
> elaborate than you need.  For instance, I do a lot of work to allow the name
> of the flag file to be entered in a number of different ways; you could just
> hard-code this to a known name (in function "setFlagFileName").
>
> Feel free to contact me if you would like some help getting this to work.
>
> Devon
>
> On 1/15/08, bill lam < [EMAIL PROTECTED]> wrote:
> >
> > I think that this is not possible for that running J instance alone. The
> > reason
> > is J is single thread so that while running the looping code, it can not
> > process
> > gui messages. Or you may test for a certain file periodically. If that
> > file is
> > deleted, then exit the loop.
> >
> > David Porter wrote:
> > > I have a loop that processes around a hundred files.  Once started, it
> > > must continue or, you must stop it using one of several ugly methods
> > > from the operating system.
> > >
> > > I put in the break. control word that looks at a variable  to enable a
> > > way to break out of the loop.  I thought setting that variable with a
> > > button on the form would be a good idea, but all I get when I try this
> >
> > > while the loop is running is the Windows "boink" .  Is there a good,
> > or
> > > any, way to set this variable while the loop is running?
> > >
> > > Dave Porter
> > > ----------------------------------------------------------------------
> >
> > > For information about J forums see http://www.jsoftware.com/forums.htm
> > >
> >
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> >
>
>
>
> --
> Devon McCormick, CFA
> ^me^ at acm.
> org is my
> preferred e-mail
>



-- 
Devon McCormick, CFA
^me^ at acm.
org is my
preferred e-mail
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to