Singleton initilized twice

HI
I have a little problem here, I am doing a webserver and I put some
calculations on the singleton’s initialization and call the methods fo
this class to do some calculations for me (no active record, just
memory). The problem is the singleton is initilizing every method api
from webserver I call.
Can someone explain how can I solve this problem?

[]´s

On 03.06.2007 17:57, [email protected] wrote:

I have a little problem here, I am doing a webserver and I put some
calculations on the singleton’s initialization and call the methods fo
this class to do some calculations for me (no active record, just
memory). The problem is the singleton is initilizing every method api
from webserver I call.
Can someone explain how can I solve this problem?

Sounds like you are using CGI and thus your singleton is initialized
once for each CGI process. You need to find another mechanism to hold
your singleton - either you use FastCGI or mod-ruby or you create a
server process that is connected to via DRb from your CGI processes.

Kind regards

robert

On 3 jun, 13:59, Robert K. [email protected] wrote:

once for each CGI process. You need to find another mechanism to hold
your singleton - either you use FastCGI or mod-ruby or you create a
server process that is connected to via DRb from your CGI processes.

Kind regards

    robert

Tks, I was doing a hello worl only ehehe, and runing “ruby script/
server” on the prompt.

[email protected] wrote:

Tks, I was doing a hello worl only ehehe, and runing “ruby script/
server” on the prompt.

Then it sounds like you still have the problem. I’ve noticed the exact
same condition – a singleton getting initialized twice – and have
found a solution that works for me. (Sorry this is 10 months late, but
maybe it will help someone.)

I’m using 1.8.6-p36 on Windows.

In my case, the issue seemed related to the fact that ‘require’ behaves
badly if you happen to include the same file multiple times using
different path specifications (e.g., relative vs. absolute vs.
yet-another-relative). In those cases, the code in the file being
‘required’ gets executed each time a ‘new’ path formulation is used,
even though the same physical file is being referenced.

I addressed this by being careful to always File.expand_path(…) on the
path before doing a ‘require’, e.g.,

require File.expand_path(’…/…/some_file_with_a_singleton_class.rb’)

instead of

require ‘…/…/some_file_with_a_singleton_class.rb’

I should that, in my case, there was a chance the multiple requires
were being done on different threads. But, offhand, I don’t think they
were.

So, I guess the moral is: Singleton users, beware the require
‘relative_path’