Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #64527
| Path | csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'wednesday,': 0.07; '22,': 0.09; 'computed': 0.09; 'executed': 0.09; 'mess': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.12; 'jan': 0.12; '23,': 0.16; 'creation.': 0.16; 'defined.': 0.16; 'pythonic': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'right:': 0.16; 'singleton': 0.16; 'sqlite': 0.16; 'stored.': 0.16; ':-)': 0.16; 'wrote:': 0.18; 'app': 0.19; 'module': 0.19; 'thu,': 0.19; 'import': 0.22; 'header:User-Agent:1': 0.23; 'expanded': 0.24; 'integer': 0.24; 'received:comcast.net': 0.24; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'chris': 0.29; 'am,': 0.29; 'object.': 0.31; 'once,': 0.31; 'second,': 0.31; 'file': 0.32; 'themselves': 0.32; 'interface': 0.32; 'running': 0.33; 'subject:from': 0.34; 'created': 0.35; 'except': 0.35; 'transaction': 0.35; 'late': 0.35; 'no,': 0.35; 'one,': 0.35; 'but': 0.35; 'there': 0.35; 'accessing': 0.36; 'january': 0.37; 'las': 0.37; 'to:addr:python-list': 0.38; 'anything': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'free': 0.61; 'matter': 0.61; 'first': 0.61; 'times': 0.62; 'default': 0.69; 'exclusive': 0.81; 'imagination': 0.84; 'persistent': 0.84; 'wish.': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Ned Batchelder <ned@nedbatchelder.com> |
| Subject | Re: SIngleton from __defaults__ |
| Date | Wed, 22 Jan 2014 14:18:19 -0500 |
| References | <26ff768d-349c-48cd-a46f-25343807e18a@googlegroups.com> <mailman.5843.1390407541.18130.python-list@python.org> <d4053869-c668-4b5d-8e58-25b3650307df@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | c-50-133-228-126.hsd1.ma.comcast.net |
| User-Agent | Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 |
| In-Reply-To | <d4053869-c668-4b5d-8e58-25b3650307df@googlegroups.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5848.1390418313.18130.python-list@python.org> (permalink) |
| Lines | 45 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1390418313 news.xs4all.nl 2937 [2001:888:2000:d::a6]:45765 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:64527 |
Show key headers only | View raw
On 1/22/14 11:37 AM, Asaf Las wrote: > 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(). No, the value for a function argument's default is computed once when the function is defined. Chris is right: get_singleton will always return the same object. > For second, again it is free to create it whenever someone (thread) > wish. Chris is right here, too: modules are themselves singletons, no matter how many times you import them, they are only executed once, and the same module object is provided for each import. > > 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 > -- Ned Batchelder, http://nedbatchelder.com
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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