Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #64510

Re: SIngleton from __defaults__

Newsgroups comp.lang.python
Date 2014-01-22 08:37 -0800
References <26ff768d-349c-48cd-a46f-25343807e18a@googlegroups.com> <mailman.5843.1390407541.18130.python-list@python.org>
Message-ID <d4053869-c668-4b5d-8e58-25b3650307df@googlegroups.com> (permalink)
Subject Re: SIngleton from __defaults__
From Asaf Las <roegltd@gmail.com>

Show all headers | View raw


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....@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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

SIngleton from __defaults__ Asaf Las <roegltd@gmail.com> - 2014-01-22 08:07 -0800
  Re: SIngleton from __defaults__ Chris Angelico <rosuav@gmail.com> - 2014-01-23 03:18 +1100
    Re: SIngleton from __defaults__ Asaf Las <roegltd@gmail.com> - 2014-01-22 08:37 -0800
      Re: SIngleton from __defaults__ 88888 Dihedral <dihedral88888@gmail.com> - 2014-01-22 09:23 -0800
      Re: SIngleton from __defaults__ Ned Batchelder <ned@nedbatchelder.com> - 2014-01-22 14:18 -0500
        Re: SIngleton from __defaults__ Asaf Las <roegltd@gmail.com> - 2014-01-22 11:52 -0800
      Re: SIngleton from __defaults__ Johannes Schneider <johannes.schneider@galileo-press.de> - 2014-01-23 14:36 +0100
      Re: SIngleton from __defaults__ Dave Angel <davea@davea.name> - 2014-01-23 11:56 -0500
      Re: SIngleton from __defaults__ Terry Reedy <tjreedy@udel.edu> - 2014-01-23 19:10 -0500
      Re: SIngleton from __defaults__ Johannes Schneider <johannes.schneider@galileo-press.de> - 2014-01-24 09:20 +0100
    Re: SIngleton from __defaults__ Asaf Las <roegltd@gmail.com> - 2014-01-22 13:10 -0800
    Re: SIngleton from __defaults__ Asaf Las <roegltd@gmail.com> - 2014-01-22 14:34 -0800

csiph-web