SIngleton from __defaults__
Asaf Las
roegltd at gmail.com
Wed Jan 22 11:37:36 EST 2014
More information about the Python-list mailing list
Wed Jan 22 11:37:36 EST 2014
- Previous message (by thread): SIngleton from __defaults__
- Next message (by thread): SIngleton from __defaults__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Wednesday, January 22, 2014 6:18:57 PM UTC+2, Chris Angelico wrote: > On Thu, Jan 23, 2014 at 3:07 AM, Asaf Las <r.... at gmail.com> wrote: > > Why not simply: > def get_singleton(x = SomeClass()): > return x > Or even: > singleton = SomeClass() > ? Neither of the above provides anything above the last one, except > for late creation. > > ChrisA Actually need was to have some interface to running independent threads to give same and once created object always. For first - SomeClass's object will be created whenever there will be call to get_singleton(). For second, again it is free to create it whenever someone (thread) wish. Hmmm, use case was to create persistent counter in multithreaded app accessing single file where incrementing integer is stored. When my imagination expanded it onto multiprocessing mess i ended up using sqlite access to DB in exclusive transaction mode. But this was not pythonic :-) Asaf
- Previous message (by thread): SIngleton from __defaults__
- Next message (by thread): SIngleton from __defaults__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list