Glen Holcomb
8/15/2008 4:44:00 PM
[Note: parts of this message were removed to make it a legal post.]
On Thu, Aug 14, 2008 at 1:27 PM, Glen Holcomb <damnbigman@gmail.com> wrote:
> On Thu, Aug 14, 2008 at 12:24 PM, Adam Shelly <adam.shelly@gmail.com>
> wrote:
>
> > On 8/14/08, Glen Holcomb <damnbigman@gmail.com> wrote:
> > > On Thu, Aug 14, 2008 at 8:38 AM, Mateusz Tybura <wujciol@gmail.com>
> > wrote:
> > > > Glen Holcomb wrote:
> > > > > Is there an easy/clean way to start a new process in Windows that
> > will
> > > > > execute just a section of code? I've tried win32-process but it
> > spawns
> > > > > a new version of the entire script which doesn't help in my
> > situation.
> > > >
> > > > Try to use ruby threads. Example
> > > > ...
> > >
> > > I'm having an
> > > issue where it appears that some combination of wx-ruby, win32ole, and
> > the
> > > garbage collector are causing my app to hang. I was hoping to execute
> > the
> > > win32ole code in a separate process in hopes of avoiding the hanging
> > > problem.
> >
> > My first thought was you could make your own fork-like functionality.
> > But after I cooked up an example, I realized that the simpler thing
> > might be to just extract the section of code in question to a separate
> > script, and launch that in a new process with `start
> > separate_script.rb input_data`
> > Just in case it's useful, here's my initial solution:
> > -Adam
> > --------
> > require 'win32ole'
> > Datafile = "fork.dump"
> > done = false
> > do_ole = ARGV.shift
> > data,result=0,0
> >
> > def oleprocess data
> > excel = WIN32OLE.new("excel.application") #your ole app here!
> > workbook = excel.Workbooks.Add();
> > excel.Range("a1")['Value'] = data;
> > excel.Range("a2")['Value'] = "=a1*a1";
> > result = excel.Range("a2")['Value']
> > excel.ActiveWorkbook.Close(0);
> > excel.Quit();
> > result
> > end
> >
> > if (do_ole == "-o")
> > p "in new process"
> > File.open(Datafile,"rb"){|fp|data = Marshal.load(fp)}
> > result = oleprocess(data)
> > File.open(Datafile,"wb"){|fp|Marshal.dump(result,fp)}
> > exit
> > else
> > data = 42 #initial_processing_here. data could be arbitrarily complex
> > File.open(Datafile,"wb"){|fp|Marshal.dump(data,fp)}
> > timestamp = File.mtime(Datafile)
> > p "launching new process"
> > system("start ruby #{__FILE__} -o")
> > until done
> > print '.'; sleep(0.1) #do gui stuff and other work here while you
> > are waiting...
> > if (File.mtime(Datafile) > timestamp) #other process is done
> > File.open(Datafile,"rb"){|fp|result = Marshal.load(fp)}
> > puts "\nsquare of #{data} is #{result}"
> > done = true
> > end
> > end
> > end
> >
> >
> Thanks guys, I appreciate it but it would appear the problem only occurs on
> the Windows Server 2003 machine I was testing on. It works fine in XP
> which
> is a bit strange.
>
> --
> "Hey brother Christian with your high and mighty errand, Your actions speak
> so loud, I can't hear a word you're saying."
>
> -Greg Graffin (Bad Religion)
>
Actually the problem has re-surfaced. Basically what I need is fork
functionality. I have a small bit of code that I need to run as a separate
process. It would solve two problems if I could achieve this:
1) The code is a bit slow as it uses win32ole so the app wouldn't appear to
stall
2) Separate heap/object space will hopefully fix the problem with the gui
becoming totally unresponsive.
I will probably have to resort to system although I'd rather not wait for
the code to finish execution as the results don't really matter to the main
thread of execution, and it takes a while.
--
"Hey brother Christian with your high and mighty errand, Your actions speak
so loud, I can't hear a word you're saying."
-Greg Graffin (Bad Religion)