Re: [jruby-user] Eliminate Startup Delay ?
Chris Seaton <[email protected]>
| Newsgroups | gmane.comp.lang.jruby.user |
|---|---|
| Message-ID | <[email protected]> |
Hello Robin, Your idea is in theory a good one, and it has been implemented in a couple of different ways as Nailgun and Drip https://github.com/jruby/jruby/wiki/Improving-startup-time. Your particular proposed solution, in Ruby, has additional drawbacks in that each script isn’t going to get a fresh interpreter state is it? Any modules, classes, global variables, threads, monkey patches etc created in one script will hang around for the next one. Chris On 19 Sep 2014, at 22:38, Robin McKay <[email protected]> wrote: > I have been very tempted recently to give up JRuby in favour of Python. > Part of the reason is that I have been dabbling with Arduinos and the > Arduino community is more likely to be familiar with Python. And the > other part is the JRuby startup delay which is painfully obvious after > using Python for an hour. > > Then it occurred to me that the startup delay could be avoided by > preventing JRuby from exiting when a program finished. > > This short code is a first crude attempt to achieve that and it seems to > work. Indeed it runs the short test program so fast that I lose track of > whether I have pressed return. And it seems to catch load errors, syntax > errors, runtime errors and java errors (in a much larger program that I > tried). > > I have little doubt that a more experienced JRuby programmer will see > scope for many improvements. > > It would be nice if every possible exception could be trapped with a > single RESCUE clause - but I don't know how to do that. > > ========== > > ScriptRunner.rb > > [code] > def runScript > begin > # load is used because require would only load the script once > load $jscriptName > # it is assumed that the script contains a method called > scriptStart > scriptStart > rescue ScriptError # catches load and syntax errors > puts "SCRIPT ERROR A" > puts $! > rescue NativeException # catches Java errors > puts "SCRIPT ERROR B" > puts $! > rescue # catches runtime errors > puts "SCRIPT ERROR C" > puts $! > end > end > > puts > puts "Starting ScriptRunner" > > $jscriptName = "./test.rb" > > while true > puts > puts "Press Return" > xxx = gets > runScript > puts "Done" > end > [/code] > > ============= > > test.rb > > [code] > def scriptStart > puts "Hey - here is testing" > xxx = 8 / 1 > puts xxx > end > [/code] > > -- > Posted via http://www.ruby-forum.com/. > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email