Fwd: Segmentation fault on returning a value

96 views
Skip to first unread message

Eugen Funk

unread,
Apr 21, 2011, 2:58:53 PM4/21/11
to rubyp...@googlegroups.com
Hello guys,

I tried to integrate rubypython into my program, but receive segmentatinos faults:
<code>
/var/lib/gems/1.8/gems/rubypython-0.5.1/lib/rubypython/pyobject.rb:114: [BUG] Segmentation fault
ruby 1.8.7 (2010-06-23 patchlevel 299) [i686-linux]
</code>

I use RubyPython inside a method in a radiant-extension:
Method:
<code>
def train_and_predict(inputs, labels, iterations)
    RubyPython.start #start python execution here
    ...
    res=w.train_and_predict(inputs, labels)
    RubyPython.stop
    return res
end
</code>
on returning the "res"-variable, the segmentation fault appears. The data in "res" is correct, which means that my method run well.

Can somone give me a hint on that? Would be great!

Thank you very much in advance!

Eugen

ps:I could not discover a possibility to extract the stack-trace. If someone has an idea on that, I would really like to hear it.




Zach Raines

unread,
Apr 21, 2011, 3:02:48 PM4/21/11
to RubyPython
Eugen,

Try the following:

<code>
def train_and_predict(inputs, labels, iterations)
RubyPython.start #start python execution here
...
res=w.train_and_predict(inputs, labels).rubify

RubyPython.stop
return res
end
</code>

My guess is that the res variable holds a wrapped python object which
is garbage collected when you stop the RubyPython interpreter. The
above could should work since it converts the return value to a Ruby
type before stopping the interpreter. You might want to consider just
starting the interpreter at the beginning of program execution and
stopping it at the end as there is overhead associated with each call
to Rubypython.start and Rubypython.stop. Let me know if that helps or
if you have anymore questions.

-Zach

Eugen

unread,
May 7, 2011, 1:01:12 PM5/7/11
to RubyPython
Cool!
rubify did the trick!
Thank you!!!

Eugen

unread,
May 7, 2011, 1:28:18 PM5/7/11
to RubyPython
Ok, now it works perfectly. I axtracted the value on the pointer
adress, befor it gets cleaned up.
Thank you for the hints!

pres=w.train(...).rubify
res=RubyPython::Conversion.ptorInt(pres)

did finally the trick.

Humiro

unread,
Jun 14, 2011, 4:59:34 PM6/14/11
to RubyPython
Sorry. I just started using this gem (and I know very little python)
and I am having a similar issue. However, I only get this error when I
reload the page. It works ok when I load it the first time. Also can
RubyPython import any module. I have a feeling that the trouble I am
having is because I am trying to import pylab and I believe I read
somewhere RubyPython will only work with "simple" modules. Please
correct me if I am wrong.

Here is my code.

RubyPython.start
x=RubyPython.import "pylab"
x.plot([1,2,3]).rubify
RubyPython.stop


When I take out the x.plot line it still breaks which is why I think
pylab is the culprit. If I import string (and again leave out the plot
line) it works fine.

Again I just started using this so any advice will be helpful.

Humberto

Eugen Funk

unread,
Jun 14, 2011, 5:16:41 PM6/14/11
to rubyp...@googlegroups.com
Well, since the plot method is using OS-handles you should consider using visualization modules written for ruby.
See http://www.gnuplot.info/screenshots/index.html#demos
for examples.  I hope this helps you out.

cheers
eugen





2011/6/14 Humiro <hct...@gmail.com>
--
You received this message because you are subscribed to the Google Groups "RubyPython" group.
To post to this group, send email to rubyp...@googlegroups.com.
To unsubscribe from this group, send email to rubypython+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubypython?hl=en.


Humberto Talavera

unread,
Jun 14, 2011, 6:13:20 PM6/14/11
to rubyp...@googlegroups.com
I have come across gnuplot and it actually produces the graphs I am seeking but I don't like the fact that it saves the graphs locally since I plan on producing several. I am currently using GoogleVisualr which uses the google visual api and it works great but unfortunately the types of graphs that can be produced is minimal. I am looking for boxplots and histograms.

Searching the web for plotting libraries led me to matplotlib,pylab which lead me to rubypython. However
from your response it sounds like using rubypython to produce the graphs needed is either discouraged or not possible???



Humberto

Zach Raines

unread,
Jun 15, 2011, 6:13:50 PM6/15/11
to rubyp...@googlegroups.com

Sorry.  I'm currently on vacation and don't have my computer with me.  Could you post the exact error you see? I'll try to take a look at it as soon as I get home. 

Rubypython can be a bit finicky with the more complex modules sometimes,  but it may be possible to get it working.

-Zach

Reply all
Reply to author
Forward
0 new messages