There is a ruby wrapper available for vtk which works, more or less,
fine. For those who are not familiar with vtk, it is avisualisation
library written in c++ and the output is a native window showing some
interactive OpenGL graphics.
Here is where the problem comes: iren.start() starts a new thread in
c++, while, I am trying to run the script in irb and interactively
change the objects properties and see the live results in the OpenGL
window. Unfortunately, after iren.start() ruby goes to a deep sleep.
This is the irb output:
?> iren.Start()
which obviously does not let me to enter any more commands unless I
close the window:
=> nil
which is too late for manipulating objects interactively.
It is surprising when a multi-threaded c++ library is single-threaded
after wrapping to ruby. If this does something have to do with ruby not
supporting native threads, perhaps it is a big sacrifice for
portability.
What is the best way to have irb command line, while also having the
graphics rendering window?
On Fri, 2006-11-10 at 02:36 +0900, Aureliano B. wrote:
?> winthr = Thread.new { iren.Start() }
Still no command line. All I want is a command line with access to the
the objects in the running thread.
Well, it looks like something in the library is blocking the calling
process (and all Ruby’s green threads) completely. If so, it’s probably
something you’d have to talk to the binding’s maintainer about.
I did just try to install VTK but it barfed horribly on my Linux box so
I’m afraid I can’t be much more help.
You do not need to have access to this library, it can be emulated
easily: Assume you want to run a very long process names
VeryLongProcess(). I want a command line when VeryLongProcess() is
running and I want this command line to have acees to all the objects
that VeryLongProcess() has access to them.
Assuming you mean ‘process’ in the sense of ‘something happening in
Ruby’, then the thread thing I suggested should work. If OTOH I’m
missing something and you’re referring to actual processes, then it gets
more involved…
Still no command line. All I want is a command line with access to the
the objects in the running thread.
You do not need to have access to this library, it can be emulated
easily: Assume you want to run a very long process names
VeryLongProcess(). I want a command line when VeryLongProcess() is
running and I want this command line to have acees to all the objects
that VeryLongProcess() has access to them.
On Thu, 09 Nov 2006 18:21:38 -0000, Aureliano B. [email protected]
wrote:
It doesn’t allow you to add any more command lines unless the
never-ending while-loop is over.
True.
Wrapping this in a thread does not help it too:
Thread.new{
i = 1
while 1
puts i
end
}
Apart from the fact that the output makes it difficult to type, that
works
fine for me, with one small change - you need to declare ‘i’ before you
start the thread - otherwise, it’ll be local to the block you run in the
thread. So try (rubified a bit):
i = 1
Thread.new { loop { puts i } }
You’ll get lots of '1’s printed out. If you just jump in and type ‘i =
2’
and hit return, the '1’s become '2’s. Does that not work for you?
From: Aureliano B. [email protected]
Subject: Re: Ruby and threads: a VTK example
Date: Fri, 10 Nov 2006 03:21:38 +0900
Message-ID: [email protected]
It doesn’t allow you to add any more command lines unless the
never-ending while-loop is over. Wrapping this in a thread does not help
it too:
What is your OS ?
If it is Windows, your trouble may depends on console I/O.
Console I/O of Win (e.g. to get a conmmand line on IRB)
blocks thread-switching of Ruby.
It doesn’t allow you to add any more command lines unless the
never-ending while-loop is over. Wrapping this in a thread does not help
it too:
What is your OS ?
If it is Windows, your trouble may depends on console I/O.
Console I/O of Win (e.g. to get a conmmand line on IRB)
blocks thread-switching of Ruby.
Please see [ruby-talk:223935] also.
Hidetoshi,
The OS is WinXP, I have also tried IRB with eclipse as an external tool
with no luck. What Ross described does not work on windows as he has
ruby on a linux box. The example you mentioned in runy-talk was done
with tk. Is there any ways or doing this in simple dos command prompt
(or eclipse)? I expected ruby to me more portable than this!
From: Aureliano B. [email protected]
Subject: Re: Ruby and threads: a VTK example
Date: Sat, 11 Nov 2006 02:18:18 +0900
Message-ID: [email protected]
The example you mentioned in runy-talk was done
with tk. Is there any ways or doing this in simple dos command prompt
(or eclipse)?
I’m sorry, but I have no idea. If I had, I didn’t make irbtkw.rbw.
Probably, it requires rewriting IRB::StdioInputMethod#gets.
I don’t know how it has to be changed, because I’m not familiar with
programing on Windows.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.