[Erp5-dev] Problem while logging into unit test

Yoshinori Okuji yo at nexedi.com
Tue Nov 6 03:20:30 CET 2007


On Monday 05 November 2007 17:48, Pelletier Vincent wrote:
> Le Lundi 5 Novembre 2007 16:12, Jérome Perrin a écrit :
> > Łukasz Nowak a écrit :
> > > "/usr/lib/zope/lib/python/Products/CMFCore/FSPythonScript.py", line
> >
> > Unfortunatly this currently breaks FSPythonScripts.
>
> BTW, this code looks quite bad, because it reads volatile values. Under
> heavy memory load - compared to connection's object cache size - volatile
> tends to disapear at any time, including inside the scope of a python
> function. This causes statements like
>   self._v_foo = 1
>   print self._v_foo
> to fail with AttributeError - if unlucky enough.

This is not true. I describe some principles:

- volatile attributes are stored in connection caches.

- a connection cache is per thread.

- a connection cache may be invalidated only at transaction boundaries 
(including savepoints or sub-transactions).

- a connection cache may not be invalidated implicitly (e.g. different from 
Python's garbase collection). You must claim where you want to do explicitly 
in an execution path (of course, it could be implicit in the sense that such 
code can be derived from a third-party add-on, but this is not done 
automatically anyway).

So,

>   self._v_foo = 1
>   print self._v_foo

this never raise AttributeError.

Volatile attributes never disappear suddenly, in a sense that an invalidation 
activity may or may not invade between lines of your code automatically.

Volatile attributes can disappear in the following cases:

- When you change a connection (e.g. reopen or publishing a new request).

- When you call cacheMinimize on a connection explicitly.

- When you call a transaction commit/abort/savepoint.

- When you invoke a piece of code which is not under your control (because it 
might call, for example, get_transaction.commit(1)).

Please don't deprecate the usage of volatile attributes. They are quite useful 
in some cases where other mechanisms may not work efficiently. You just need 
to understand the nature of volatile attributes, to make them really useful.

YO
-- 
Yoshinori Okuji, Nexedi CTO
Nexedi: Consulting and Development of Free / Open Source Software
http://www.nexedi.com
ERP5: Full Featured High End Open Source ERP
http://www.erp5.com
ERP5 Wiki: Developer Zone for ERP5 Community
http://www.erp5.org



More information about the Erp5-dev mailing list