problem of feedtools with jruby

View: New views
8 Messages — Rating Filter:   Alert me  

problem of feedtools with jruby

by yapex :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi, guys
    I play feedtools with jruby, but get exceptions like

=======================================
D:\ruby-workspace\learning>jruby feed_tools_exam.rb
Description: Mars Today Top Stories
D:/jruby-1.1.3/lib/ruby/gems/1.8/gems/feedtools-0.2.29/lib/feed_tools/feed_item.
rb:67:in `each_object': ObjectSpace is disabled; each_object will only work with
 Class, pass +O to enable (RuntimeError)
        from D:/jruby-1.1.3/lib/ruby/gems/1.8/gems/feedtools-0.2.29/lib/feed_too
ls/feed_item.rb:67:in `feed'
        from D:/jruby-1.1.3/lib/ruby/gems/1.8/gems/feedtools-0.2.29/lib/feed_too
ls/feed_item.rb:141:in `configurations'
        from D:/jruby-1.1.3/lib/ruby/gems/1.8/gems/feedtools-0.2.29/lib/feed_too
ls/feed_item.rb:1757:in `time'
        from D:/jruby-1.1.3/lib/ruby/gems/1.8/gems/feedtools-0.2.29/lib/feed_too
ls/feed.rb:2446:in `entries'
        from D:/jruby-1.1.3/lib/ruby/gems/1.8/gems/feedtools-0.2.29/lib/feed_too
ls/feed.rb:2445:in `sort'
        from D:/jruby-1.1.3/lib/ruby/gems/1.8/gems/feedtools-0.2.29/lib/feed_too
ls/feed.rb:2445:in `entries'
========================================================

Source code is very sample:
====================================
require 'rubygems'
require "feed_tools"

URL = "http://www.marstoday.com/rss/mars.xml"
FeedTools.configurations[:feed_cache] = nil
feed = FeedTools::Feed.open(URL)
puts "Description: #{feed.title}"

feed.entries.each {|item| puts item.title}
=================================

    Anyone can help me ?
--
YaPEX
Shanghai, China
http://friendfeed.com/yapex

Re: problem of feedtools with jruby

by jmettraux :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, Jul 23, 2008 at 12:19 PM, Yin AnPing <yapex.yin@...> wrote:

>
>     I play feedtools with jruby, but get exceptions like
>
> =======================================
> D:\ruby-workspace\learning>jruby feed_tools_exam.rb
> Description: Mars Today Top Stories
> D:/jruby-1.1.3/lib/ruby/gems/1.8/gems/feedtools-0.2.29/lib/feed_tools/feed_item.
> rb:67:in `each_object': ObjectSpace is disabled; each_object will only work
> with
>  Class, pass +O to enable (RuntimeError)

Did you try with

jruby +O feed_tools_exam.rb

as advertised by the error message ?


Best regards,

--
John Mettraux - http://jmettraux.wordpress.com

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: problem of feedtools with jruby

by yapex :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Yes, but I still get error message:
jruby: unknown option +O

On Wed, Jul 23, 2008 at 11:22 AM, John Mettraux <jmettraux@...> wrote:
On Wed, Jul 23, 2008 at 12:19 PM, Yin AnPing <yapex.yin@...> wrote:
>
>     I play feedtools with jruby, but get exceptions like
>
> =======================================
> D:\ruby-workspace\learning>jruby feed_tools_exam.rb
> Description: Mars Today Top Stories
> D:/jruby-1.1.3/lib/ruby/gems/1.8/gems/feedtools-0.2.29/lib/feed_tools/feed_item.
> rb:67:in `each_object': ObjectSpace is disabled; each_object will only work
> with
>  Class, pass +O to enable (RuntimeError)

Did you try with

jruby +O feed_tools_exam.rb

as advertised by the error message ?


Best regards,

--
John Mettraux - http://jmettraux.wordpress.com

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email





--
YaPEX
Shanghai, China
http://friendfeed.com/yapex

Re: problem of feedtools with jruby

by jmettraux :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, Jul 23, 2008 at 12:24 PM, Yin AnPing <yapex.yin@...> wrote:
> Yes, but I still get error message:
> jruby: unknown option +O

Maybe

./bin/jruby -J-Djruby.objectspace.enabled=true feed_tools_exam.rb

seen on :

http://wiki.jruby.org/wiki/Performance_Tuning


Best regards,

--
John Mettraux - http://jmettraux.wordpress.com

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: problem of feedtools with jruby

by Charles Oliver Nutter-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Yin AnPing wrote:

> Hi, guys
>     I play feedtools with jruby, but get exceptions like
>
> =======================================
> D:\ruby-workspace\learning>jruby feed_tools_exam.rb
> Description: Mars Today Top Stories
> D:/jruby-1.1.3/lib/ruby/gems/1.8/gems/feedtools-0.2.29/lib/feed_tools/feed_item.
> rb:67:in `each_object': ObjectSpace is disabled; each_object will only
> work with
>  Class, pass +O to enable (RuntimeError)

Oops, sorry about that, it's a bad error message. The correct flag to
turn on full ObjectSpace is -X+O. We moved it under the -X options to
avoid any future conflict with normal Ruby obtions.

I'll fix the error.

- Charlie

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: problem of feedtools with jruby

by yapex :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

thanks ! It works !

On Wed, Jul 23, 2008 at 12:32 PM, Charles Oliver Nutter <charles.nutter@...> wrote:
Yin AnPing wrote:
Hi, guys
   I play feedtools with jruby, but get exceptions like

=======================================
D:\ruby-workspace\learning>jruby feed_tools_exam.rb
Description: Mars Today Top Stories
D:/jruby-1.1.3/lib/ruby/gems/1.8/gems/feedtools-0.2.29/lib/feed_tools/feed_item.
rb:67:in `each_object': ObjectSpace is disabled; each_object will only work with
 Class, pass +O to enable (RuntimeError)

Oops, sorry about that, it's a bad error message. The correct flag to turn on full ObjectSpace is -X+O. We moved it under the -X options to avoid any future conflict with normal Ruby obtions.

I'll fix the error.

- Charlie


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

  http://xircles.codehaus.org/manage_email





--
YaPEX
Shanghai, China
http://friendfeed.com/yapex

Re: problem of feedtools with jruby

by yapex :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

another way to run it
thanks everybody !
================================
require 'rubygems'
require "feed_tools"
require 'jruby'

JRuby.objectspace=true

URL = "http://www.marstoday.com/rss/mars.xml"
FeedTools.configurations[:feed_cache] = nil
feed = FeedTools::Feed.open(URL)
puts "Description: #{feed.title}\n"

feed.entries.each {|item| puts item.title}
=================================

On Wed, Jul 23, 2008 at 12:52 PM, Yin AnPing <yapex.yin@...> wrote:
thanks ! It works !


On Wed, Jul 23, 2008 at 12:32 PM, Charles Oliver Nutter <charles.nutter@...> wrote:
Yin AnPing wrote:
Hi, guys
   I play feedtools with jruby, but get exceptions like

=======================================
D:\ruby-workspace\learning>jruby feed_tools_exam.rb
Description: Mars Today Top Stories
D:/jruby-1.1.3/lib/ruby/gems/1.8/gems/feedtools-0.2.29/lib/feed_tools/feed_item.
rb:67:in `each_object': ObjectSpace is disabled; each_object will only work with
 Class, pass +O to enable (RuntimeError)

Oops, sorry about that, it's a bad error message. The correct flag to turn on full ObjectSpace is -X+O. We moved it under the -X options to avoid any future conflict with normal Ruby obtions.

I'll fix the error.

- Charlie


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

  http://xircles.codehaus.org/manage_email





--
YaPEX
Shanghai, China
http://friendfeed.com/yapex



--
YaPEX
Shanghai, China
http://friendfeed.com/yapex

Re: problem of feedtools with jruby

by Michael Guterl :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, Jul 23, 2008 at 12:56 AM, Yin AnPing <yapex.yin@...> wrote:

> another way to run it
> thanks everybody !
> ================================
> require 'rubygems'
> require "feed_tools"
> require 'jruby'
>
> JRuby.objectspace=true
>
> URL = "http://www.marstoday.com/rss/mars.xml"
> FeedTools.configurations[:feed_cache] = nil
> feed = FeedTools::Feed.open(URL)
> puts "Description: #{feed.title}\n"
>
> feed.entries.each {|item| puts item.title}
> =================================

I don't mean to hijack this thread and we can move it elsewhere if
necessary, but I am surprised to see such a "simple" library using
ObjectSpace.each_object.  I know the JRuby team made the decision to
turn ObjectSpace.each_object off by default because of a large
performance hit and the fact that ObjectSpace.each_object is seldom
used.

If I recall correctly test/unit used to use each_object and it was
able to be patched to avoid using it entirely, anyone remember if this
is correct?

The offending method and author's comment prior to it are listed at
the bottom of this email and at http://pastie.org/242073.

I guess I could ask elsewhere, but I do not understand the author's
motivation described in the comment below.  I am assuming there is a
simple hierarchy between feeds and feed items with a feed being the
parent of a feed item.  I am curious what type of havoc storing the
parent in the feed item could cause with GC?

Storing a reference to the parent object of a child object in a
hierarchy seems like a fairly common thing to do, is it not?

Also, I know that JRuby uses a different GC than MRI, would JRuby's GC
mechanism be less likely to experience the pitfalls (which I am still
trying to understand) than MRI?

I just guess I am surprised to see ObjectSpace.each_object used in
such a simple situation.  I always assumed most use cases could be
implemented using some other means.

Thanks,
Michael Guterl

<<-CODE

# Returns the parent feed of this feed item
# Warning, this method may be slow if you have a
# large number of FeedTools::Feed objects.  Can't
# use a direct reference to the parent because it plays
# havoc with the garbage collector.  Could've used
# a WeakRef object, but really, if there are multiple
# parent feeds, something is going to go wrong, and the
# programmer needs to be notified.  A WeakRef
# implementation can't detect this condition.

def feed
  parent_feed = nil
  ObjectSpace.each_object(FeedTools::Feed) do |feed|
    if feed.instance_variable_get("@entries").nil?
      feed.items
    end
    unsorted_items = feed.instance_variable_get("@entries")
    for item in unsorted_items
      if item.object_id == self.object_id
        if parent_feed.nil?
          parent_feed = feed
          break
        else
          raise "Multiple parent feeds found."
        end
      end
    end
  end
  return parent_feed
end

CODE

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


LightInTheBox - Buy quality products at wholesale price