December 16, 2008 at 21:54timka.orgsaysshaf: I use __new__ which always returns the single instance stored in a class attribute
December 16, 2008 at 21:58shafyeah but what's to stop you from executing the script using another python intepreter ? Singleton breaks.
December 16, 2008 at 21:59shafIt's just that singleton is the simplest pattern to understand but can be tricky to implement if you don't understand your compiler/interptr
December 16, 2008 at 22:12timka.orgsaysshaf: Another interpreter runs another instance of your program which has its own singleton instance.
December 16, 2008 at 22:55timka.orgsaysshaf: I mean Singleton is usually limited to one process no matter what language you use, so multiple *program* instances is out of scope.
December 16, 2008 at 22:58shaftimka_org yep. I know all this already. But as any good programmer would know, singleton in practice is not guarenteed
December 16, 2008 at 22:58shafthis is why in any good production environment. Singleton is frowned upon
December 16, 2008 at 23:07timka.orgsaysYeah, in our production environment at work two instances of our app can fuck up the DB just because nobody cared about proper locking
December 16, 2008 at 23:10timka.orgsaysIt's about thread-safety inside single process, but you were talking about multiple processes
December 16, 2008 at 23:11shafhence the reason for me to have mixed feelings about it. If used - use it carefully
December 16, 2008 at 23:12shafwell some idiot programmers assume singletons to work across processes too
December 16, 2008 at 23:14timka.orgsaysAgree. And punish those who break the conventions!
December 16, 2008 at 23:18timka.orgsaysI think you can only fire or train them. Hard choice...
December 17, 2008 at 07:22muhuksayson the other hand, most of the time singleton is not really needed in practice. Surely there is one trash (per user) but I have come to...
December 17, 2008 at 07:23muhuksays...realize I don't need a singleton trash wrapper class at all. It is even making things harder to unittest.
December 17, 2008 at 07:24muhuksaysBtw, a singleton shouldn't be confused as a concurrency mechanism (especially in multi-process systems).
December 17, 2008 at 07:34timka.orgsaysAnyway, Singleton is just an object creation pattern, conceptually it has nothing to do with concurrency.
December 17, 2008 at 07:37timka.orgsaysHowever, correct implementations must be aware of the used concurrency model