|
From: Thomas B. B. <tb...@sy...> - 2001-05-18 14:02:29
|
Hi again - thanks Brian - I'm going to clarify my setup a little more here:
I have several EJBs which supports a 'validate' method. This method
basically reads a validation script (Jython script) from a database, then
looks up a BSFManager EJB (session bean) via JNDI, then passes the script
read to the BSFManager's exec method, which then in turn invokes the Jython
interpreter to execute the script.
Since the validation is run in an EJB in the AppServer, I cannot create or
manipulate threads neither from within the BSFManager EJB nor from within
the Jython script itself (as suggested below by Brian), and since the
"client" in this case is also an EJB, I cannot even create a new thread at
the client side, which then might be terminated in case of timeout.
However, I really need the timeout, since a user obviously can write a
Jython script that never halts, which then will bring the entire user
session to a halt...
Thanks again, happy jythoneering!
Thomas
> -----Original Message-----
> From: brian zimmer [mailto:bz...@zi...]
> Sent: 18. maj 2001 14:55
> To: Thomas Bang Biilmann; Jython Dev (E-mail)
> Subject: RE: [Jython-dev] Time-out an embedded Jython script
>
>
> Do you have control over the call to the BSFManager? In
> other words, I assume you are taking input from a user and
> using the Jython
> interp to exec the statement. Since you have no control over
> threads within the appserver, how about wrapping the call in a Thread
> which can perform the necessary timeout functionality within the BSF.
>
> ***** DISCLAIMER: I JUST WROTE THIS SITTING AT MY DESK, IT
> HAS __NOT__ BEEN THOUROUGHLY TESTED! *****
>
> from java.lang import Thread
>
> def timeoutexec(stmt, timeout=0):
> t = TimeoutThread(stmt)
> t.start()
> t.join(timeout)
> if t.isAlive():
> # this thread should have timed-out by now
> print "going to time out the exec()"
> t.interrupt()
> else:
> print "no need to time out the exec()"
>
> class TimeoutThread(Thread):
> def __init__(self, stmt):
> self.stmt = stmt
>
> def run(self):
> try:
> # here's where you'd really call the bsf exec()
> exec(self.stmt)
> except:
> print "timedout"
>
> if __name__ == '__main__':
> timeoutexec("import time; time.sleep(10)", 11 * 1000)
> timeoutexec("import time; time.sleep(11)", 10 * 1000)
>
> I'm not exactly sure how the BSF works, but perhaps you can
> implement something like the above and wrap all the calls.
> There's some
> overhead in setting up all these threads, but if you really
> need a timeout the above will work.
>
> > -----Original Message-----
> > From: jyt...@li...
> > [mailto:jyt...@li...]On Behalf Of
> Thomas Bang
> > Biilmann
> > Sent: Friday, May 18, 2001 3:20 AM
> > To: Jython Dev (E-mail)
> > Subject: [Jython-dev] Time-out an embedded Jython script
> >
> >
> > Hi all!
> >
> > In my quest for embedding Jython as a user-programmable
> validation language
> > within Borland AppServer 4.5, I have the following question:
> >
> > - How can I ensure that a call for the exec(...) method
> of a BSFManager is
> > allowed to run only for a limited time frame? Thus, if a
> user decides to
> > write a Jython script that never halts, the exec is
> terminated when the
> > designated time frame expires.
> >
> > Please note that - as far as I know - developer control over thread
> > management within the AppServer is NOT an option, unfortunately...
> >
> > All ideas appreciated!
> >
> > Regards,
> > Thomas
> >
> >
> > _______________________________________________
> > Jython-dev mailing list
> > Jyt...@li...
> > http://lists.sourceforge.net/lists/listinfo/jython-dev
>
>
|