6

Periodically I get this exception:

NotImplementedError: method `at' called on terminated object

on this line of code:

next if Hpricot(html).at('a')

What does this error mean? How can I avoid it?

Tom Lehman
  • 85,973
  • 71
  • 200
  • 272
  • Does it also happen if you assign the result of `Hpricot(html)` to a variable before whole loop instead of performing it every time? – Mladen Jablanović Jan 13 '11 at 08:21
  • `html` is the loop parameter, so I can't do it *before* the loop, though I could do something like `doc = Hpricot(html)` at the top of the loop and do `doc.at('a')`. I'll give this a try – Tom Lehman Jan 13 '11 at 18:59

2 Answers2

2

The library you are using makes use of a custom C extension. In the C extension, it is trying to call a method on a Ruby object which has already been garbage-collected.

This can't happen in pure Ruby, because the garbage collector will only free objects which are no longer accessible from any reference. But in C, it is possible to have a reference remaining to a Ruby object, in a place which the garbage collector doesn't check (for example, the compiler may have put a variable in a CPU register).

Alex D
  • 29,755
  • 7
  • 80
  • 126
0

It might be a linking problem. Check that you didn't link the extension twice.

Dan
  • 41
  • 2
  • By "link the extension twice", do you mean "`require` the extension twice"? (Isn't `require` designed to make sure this doesn't cause problems?) – Tom Lehman Jun 27 '11 at 17:18