Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.06; 'concurrently': 0.07; 'explicit': 0.07; 'result,': 0.07; 'session.': 0.07; 'extends': 0.09; 'objects,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'stale': 0.09; 'thread': 0.14; '23,': 0.16; 'aggressively': 0.16; 'caches': 0.16; 'concurrent': 0.16; 'iirc': 0.16; 'in-memory': 0.16; 'lie': 0.16; 'locally,': 0.16; 'operation.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'sqlalchemy': 0.16; 'subject:ORM': 0.16; 'subject:library': 0.16; 'traverse': 0.16; 'underlying': 0.16; 'unexpected': 0.16; 'url:guide': 0.16; 'url:html)': 0.16; 'wrote:': 0.18; '(not': 0.18; 'header:User- Agent:1': 0.23; 'instead.': 0.24; 'sends': 0.24; 'connected': 0.24; 'supported': 0.26; 'header:X-Complaints-To:1': 0.27; 'header :In-Reply-To:1': 0.27; 'database,': 0.30; 'network.': 0.30; 'loading': 0.31; 'monday,': 0.33; 'problem': 0.35; 'objects': 0.35; 'instances': 0.36; 'object,': 0.36; 'ryan': 0.36; 'subject:?': 0.36; 'url:org': 0.36; 'server': 0.38; 'to:addr :python-list': 0.38; 'structure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; "you're": 0.61; 'email addr:gmail.com': 0.63; 'provide': 0.64; 'more': 0.64; 'charset:windows-1252': 0.65; 'reads': 0.68; 'therefore': 0.72; 'personally.': 0.84; 'safe.': 0.84; 'subject:read': 0.84; 'received:31': 0.91; 'url:latest': 0.91; 'suited': 0.93; 'tied': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Lie Ryan Subject: Re: Python ORM library for distributed mostly-read-only objects? Date: Tue, 24 Jun 2014 00:16:36 +0100 References: <85659fdd-511b-4aea-9c4b-17a4bbb88662@googlegroups.com> <9030a8c2-2a11-4ea8-a9f0-c23d31e0d925@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 31.55.90.126 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 In-Reply-To: <9030a8c2-2a11-4ea8-a9f0-c23d31e0d925@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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1403565412 news.xs4all.nl 2930 [2001:888:2000:d::a6]:44461 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:73523 On 23/06/14 19:05, smurfix@gmail.com wrote: > On Monday, June 23, 2014 5:54:38 PM UTC+2, Lie Ryan wrote: > >> If you don't want each thread to have their own copy of the object, >> >> Don't use thread-scoped session. Use explicit scope instead. > > How would that work when multiple threads traverse the in-memory object structure and cause relationships to be loaded? > IIRC sqlalchemy's sessions are not thread safe. You're going to have that problem anyway, if it is as you said that your problem is that you don't want each thread to have their own copy, then you cannot avoid having to deal with concurrent access. Note that SQLAlchemy objects can be used from multiple thread as long as it's not used concurrently and the underlying DBAPI is thread-safe (not all DBAPI supported by SQLAlchemy are thread safe). You can detach/expunge an SQLAlchemy object from the session to avoid unexpected loading of relationships. Alternatively, if you are not tied to SQLAlchemy nor SQL-based database, then you might want to check out ZODB's ZEO (http://www.zodb.org/en/latest/documentation/guide/zeo.html): > ZEO, Zope Enterprise Objects, extends the ZODB machinery to > provide access to objects over a network. ... ClientStorage > aggressively caches objects locally, so in order to avoid > using stale data the ZEO server sends an invalidation message > to all the connected ClientStorage instances on every write > operation. ... As a result, reads from the database are > far more frequent than writes, and ZEO is therefore better > suited for read-intensive applications. Warning: I had never used ZODB nor ZEO personally.