From: Hugh Sasse Date: 2007-08-07T01:29:50+09:00 Subject: Re: Mac OSX singleton On Tue, 7 Aug 2007, Fyodor wrote: > This might be an actual bug in ruby itself. any comments? In so far as your example shows no rails code.... > > ---------- Forwarded message ---------- > From: Rails Trac > Date: Aug 6, 2007 5:40 PM > Subject: [Rails Trac] #9202: Mac OSX singleton > To: undisclosed-recipients > > > #9202: Mac OSX singleton > ----------------------+----------------------------------------------------- > Reporter: fygrave | Owner: core > Type: defect | Status: new > Priority: normal | Milestone: 1.x > Component: Railties | Version: edge > Severity: normal | Keywords: rails singleton mac osx > ----------------------+----------------------------------------------------- > There's a problem with Mac OSx singleton class. To make the story short, > the singleton doesn't work as singleton on mac osx platform. with every > request a new instance of the class is created. What are you actually using to request a new instance? > mac-2:~/rails/app/models mac$ uname -a > Darwin mac-2.local 8.10.1 Darwin Kernel Version 8.10.1: Wed May 23 > 16:33:00 PDT 2007; root:xnu-792.22.5~1/RELEASE_I386 i386 i386 > > rails gem version - 1.2.3 > > to reproduce define a class: > > foo.rb in models which would look like this: > > class Foo > include Singleton > class << self; attr_accessor :Foopipe; end That looks to me like you're creating an accessor for what is effectively a class variable, visible from any instance of this class. > > def initialize > @cmd = "/bin/sleep 2000" that's the best part of an hour. You have setup a race condition. > if self.class.Foopipe == nil then > self.class.Foopipe = IO.popen(@cmd, "r+") > self.class.KMpipe.sync = true > self.class.Foopipe.write("something) > self.class.KMpipe.flush > end > end > You create the first instance, and while it is being made, I presume, given that you don't show code, that you try to create another, but since the first one doesn't exist yet, you can start to create the second. > ... the rest of class is not relevant. > > Foopipe in this example never takes any value, and an instance of the Never? Even after 2000 seconds? Where's your proof of this statement? > class (and running proccess that could be seen with ps .. ) is created > every time when the class is created and accessed... > > -- > Ticket URL: > Rails Trac > Ruby on Rails > Hugh