Re[2]: [ZODB-Dev] lazy BTreeItems

2005-12-10 Thread Victor Safronovich
Hello Dieter Maurer,

Saturday, December 10, 2005, 12:32:35 AM, you wrote:

DM l = range(10)
DM for f in l: l.remove(f)
DM l
-- [1, 3, 5, 7, 9]

DM   Due to the much more complex BTree structures, the results
DM   of modifications during iteration might be even more surprising.
I know about this

Hello Tim Peters,

Saturday, December 10, 2005, 1:08:55 AM, you wrote:

TP The .keys(), .values(), and .items() methods of BTrees are very different
TP from those methods on dicts in that the BTree methods return lazy iterators
TP but the dict methods return lists.
I  undestand  that i need keys|values|items cast to list, and from this new list
get the new iterator.

And a funny situation

Starting debugger (the name app is bound to the top-level Zope object)
 from OFS.ObjectManager import ObjectManager
 from OFS.SimpleItem import SimpleItem
 m = ObjectManager()
 m._setObject('1',SimpleItem())
'1'
 m._setObject('2',SimpleItem())
'2'
 o_ids = m.objectIds()
 o_ids
['1', '2']
 m._delObject('1')
 o_ids
['1', '2']
 from Products.BTreeFolder2.BTreeFolder2 import BTreeFolder2
 m = BTreeFolder2()
 m._setObject('1',SimpleItem())
'1'
 m._setObject('2',SimpleItem())
'2'
 o_ids = m.objectIds()
 o_ids
OOBTreeItems object at 0x4015dca0
 list(o_ids)
['1', '2']
 m._delObject('1')
 list(o_ids)
['2']

I`ll want to migrate my large object containers from Folder to BTreeFolder2, 
but my
code have many next places:

for id in container.objectIds():
   if some_condition:
   container._delObject(id)

or

container.manage_delObjects( container.objectIds() )

Be careful with migration of such type.

-- 
Best regards,
 Victor Safronovich
 NauMen.NauDoc.SoftwareDeveloper  http://www.naumen.ru

___
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zodb-dev


Re[2]: [ZODB-Dev] Deferred notifing from one thread to another.

2005-12-10 Thread Victor Safronovich
Hello Dieter Maurer,

Saturday, December 10, 2005, 12:34:48 AM, you wrote:

DM Victor Safronovich wrote at 2005-12-9 14:33 +0500:
 ...
But when T2
still not commiting its transaction, dispatcher not see new element :(.

DM Any transaction will only see committed changes.

DM Only at transaction boundaries will a connection cache be updated
DM for modifications by other transactions.
Dieter, i know about this.

Have   you   some   situations,   when   you  need  to  know  if  transaction of
thread1  commited,  but you are in  thread2?  In other words How can i receive 
the
signal  that  transaction  in  another  thread commited( or aborted, but this is
another question)?

-- 
Best regards,
 Victor Safronovich
 NauMen.NauDoc.SoftwareDeveloper  http://www.naumen.ru

___
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zodb-dev


[ZODB-Dev] Deferred notifing from one thread to another.

2005-12-09 Thread Victor Safronovich
Hello zodb-dev!

I have a some problem, and don`t know how to solve it :(.

I have a scheduler dispatcher thread with run method

def run(self):
app = Zope2.bobo_application()
try:
scheduler = app.unrestrictedTraverse( self.scheduler_path, None )
queue = scheduler.getEventQueue( reset=True )

while not DieEvent.isSet():
if ResetEvent.isSet():
ResetEvent.clear()
app._p_jar.sync()
# refresh the queue and set new expires time
queue.refresh()

event = queue.getNextEvent()
if event and event.waitTillStart( ResetEvent ):
EventSemaphore.acquire()
event.setDaemon(True)
event.setSemaphore( EventSemaphore )
event.start()

elif not ResetEvent.isSet():
# No events left in the queue.
# Just waiting for the queue to expire.
delay = queue.expires - now()
ResetEvent.wait( delay.seconds )
ResetEvent.set()

finally:
app._p_jar.close()

and a Scheduler class with addScheduleElement method

class Scheduler(BTreeFolder2):

def addScheduleElement(self, **options):
self._setObject(self.generateId(), ScheduleElement(**options))
ResetEvent.set()

addScheduleElement  is  called  from ZServer thread.
for instance dispather thread is 'T1', and ZServer thread is 'T2'.

addScheduleElement  sets  ResetEvent  and dispatcher refreshed queue, dispatcher
called  app._p_jar.sync()  to  see modifications from other threads. But when T2
still not commiting its transaction, dispatcher not see new element :(.

I thinks if there is an afterCommitHook at transaction, i`ll use it, but it is 
not exist.

Of course i may write time.sleep( SLEEP_CONSTANT ) before app._p_jar.sync(), but
is this a good solution?

-- 
Best regards,
 Victor Safronovich
 NauMen.NauDoc.SoftwareDeveloper  http://www.naumen.ru

___
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zodb-dev


Re[2]: [ZODB-Dev] Deferred notifing from one thread to another.

2005-12-09 Thread Victor Safronovich
Hello Tim Peters,

Friday, December 9, 2005, 9:18:26 PM, you wrote:

TP [Victor Safronovich]
 ...
 Of course i may write time.sleep( SLEEP_CONSTANT ) before
 app._p_jar.sync(), but is this a good solution?

TP I can't make time to understand your problem (sorry!)
   Tim, thank you for your answer.
   
TP , but I can make time
TP to tell you that a bare time.sleep() is almost never a good solution to
TP thread problems.  time.sleep() in a _loop_ can be reliable, provided you can
TP write code to recognize when what you're waiting for has happened; this
TP approach is called polling.

TP while what I'm waiting for hasn't happened:
TP time.sleep(WHATEVER)

TP For example, when you change a persistent object, its ._p_changed attribute
TP gets set to a true value.  When the change gets committed, ._p_changed is
TP reset to a false value.  So _perhaps_ (I'm not sure -- being sure would
TP require understanding all of your problem) you could poll waiting for some
TP specific object's _p_changed to become false.

  Supper, I do the next

  def reset_hook( scheduler ):
  while scheduler._p_changed:
 time.sleep(0.05) # again time sleep :))
  ResetEvent.set()

  and
  
  def addSchedulerElement(self, **options):
self._setObject(self.generateId(), ScheduleElement(**options))
Thread(target=reset_hook, args=(self,))

  Tommorow, i`ll check how this works :).


-- 
Best regards,
 Victor Safronovich
 NauMen.NauDoc.SoftwareDeveloper  http://www.naumen.ru

___
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zodb-dev


Re: [ZODB-Dev] Class Versioning?

2005-10-29 Thread Victor Safronovich
Hello Chris Spencer,

Saturday, October 29, 2005, 7:16:43 AM, you wrote:

CS Would it be possible to support some system of class versioning in ZODB, 
CS to aid to handling modifications to source code? For instance, suppose 
CS each class definition has a __version__ attribute. Upon serialization, 
CS this version is saved for each instance. Then, if the class is updated, 
CS signified by incrementing the class's __version__, ZODB could take 
CS action, for example, by executing an optional __upgrade_to_x(self) in 
CS the new class definition.
 you can easily derive your own class from Persistent class, and add some 
system of class versioning
 to them.

 for example ( untested )

 class Persistent(_Persistent):
# attributes for version tag support
_class_version = None
_class_tag   = None
_version_tag = None

def __class_init__(self): # works only for extension classes
tags = [ self._class_version ]
for base in self.__bases__:
if hasattr( base, '_class_tag' ):
   tags.append( base._class_tag )

self._class_tag = hash( tuple(tags) )

def __setstate__( self, state ):
_Persistent.__setstate__( self, state )
if self.tagChanged():
self.doSomething()

def doSomething(self):
self._version_tag = self._class_tag

def tagChanged(self):
return self._version_tag  self._class_tag

 class A(Persistent):
_class_version = 1.3

 class B(A):
_class_version = 1.45

-- 
Best regards,
 Victor Safronovich
 NauMen.NauDoc.SoftwareDeveloper  http://www.naumen.ru

___
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zodb-dev


Re[2]: [ZODB-Dev] know the state of an object

2005-10-18 Thread Victor Safronovich
Hello Jim Fulton,

Friday, October 14, 2005, 7:01:00 PM, you wrote:

JF The long term solution to these are other related use cases is to start
JF using events in ZODB.  That is, ZODB should use zope.event to report
JF happenings of potential interest to applications.  Then applications
JF can use the event system to be notified and provide additional
JF functionality.
   May be usefull to add some simple workflow to Persistent class with
   states:
   GHOST
   UPTODATE
   CHANGED
   STICKY
   transitions:
   activate
   deactivate
   ghostify
   unghostify
   changed
   invalidate
   and others
   and to be able to add hooks to before and after transition.

-- 
Best regards,
 Victor Safronovich
 NauMen.NauDoc.SoftwareDeveloper  http://www.naumen.ru

___
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zodb-dev


Re[2]: [ZODB-Dev] afterCommitHook

2005-09-26 Thread Victor Safronovich
Hello Chris Withers,

Friday, September 23, 2005, 9:12:19 PM, you wrote:

CW Why not just use MaildropHost?
  1. Because it is *nix only, it use os.fork(), using Thread.setDaemon(1) is 
more friendly for me.
  2. Because it takes all his options from Config file, not Zodb objects.
  3. Because there is imposible to  import  mainloop from
Products.MaildropHost.maildrop.maildrop, because
Products.MaildropHost.maildrop is not package.
  4. Because  mainloop  is  the huge function, MainLoop class with small 
methods is more
  friendly for me, to subclassing from it.

  But MaildropHost is a wonderful product, and thanks to its author.

  This topic is not a zodb-dev problem and should be moved to zope-dev.
-- 
Best regards,
 Victor Safronovich
 NauMen.NauDoc.SoftwareDeveloper  http://www.naumen.ru

___
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zodb-dev


Re[2]: [ZODB-Dev] BTrees and setdefault

2005-08-28 Thread Victor Safronovich
Hello zodb-dev,

[Tim Peters]
TP Despite that the message I linked to above was written last October, there
TP are still only about a dozen total uses of setdefault() in the Python core,
TP and there are still many more lines of code in the core implementing the
TP thing than there are lines of code using it.  I remain -0 on the idea (which
TP means it's OK by me, I just prefer not to bother).  Jim's +1 wipes out any
TP number of -0 votes ;-).
+1 for adding setdefault for BTrees.

the code below

if not self._index.has_key(comp):
self._index[comp] = IOBTree()

if not self._index[comp].has_key(level):
self._index[comp][level] = IITreeSet()

self._index[comp][level].insert(id)

may change to
 
comp = self._index.setdefault( comp, IOBTree() )
level = comp.setdefault( level, IITreeSet() )
level.insert( id )

which looks much better.


-- 
Best regards,
 Victor Safronovich
 NauMen.NauDoc.SoftwareDeveloper  http://www.naumen.ru

___
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zodb-dev


Re: [ZODB-Dev] PersistentMapping glitches

2005-08-23 Thread Victor Safronovich
Hello Tim Peters,

Monday, August 22, 2005, 8:44:08 PM, you wrote:

 from BTrees.OOBTree import OOBTree 
 b = OOBTree()
 b.update(pm)
TP Traceback (most recent call last):
TP   File stdin, line 1, in ?
TP   File C:\python23\lib\UserDict.py, line 19, in __getitem__
TP def __getitem__(self, key): return self.data[key]
TP KeyError: 0

Some  workaround for me(the Collector 1873 poster) was to use data attribute of
the UserDict instances.
 from ZODB.PersistentMapping import PersistentMapping
 from BTrees.OOBTree import OOBTree
 r = OOBTree()
 r.update( PersistentMapping({1:1}).data)
 dict(r)
{1: 1}

i am using isinstance(obj, UserDict) condition now.

-- 
Best regards,
 Victor Safronovich
 NauMen.NauDoc.SoftwareDeveloper  http://www.naumen.ru

___
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zodb-dev


[ZODB-Dev] Reloading product in 2.8

2005-07-12 Thread Victor Safronovich
 
[11211695992112010853]
Function variables:
  meta=(class 'Products.Transience.TransientObject.TransientObject', ())
  klass=class 'Products.Transience.TransientObject.TransientObject' 
[TransientObject]
  newargs=built-in method __getnewargs__ of TransientObject object at 
0x02F4A170 [__getnewargs__]

  Module ZODB.serialize, line 339, in _dump
Line 7 of function _dump:
  self._p.dump(state)
Function arguments:
  self=ZODB.serialize.ObjectWriter instance at 0x03B21030
  classmeta=(class 'Products.Transience.TransientObject.TransientObject', 
())
  state={'_last_accessed': 1121169672.484, '_last_modified': 
1121169672.655, 'token': '74187034A16XXKS7Ut0', '_created': 1121169599.296, 
'_container': {('explorer', '351409078'): {'title_field': None, 'ca

PicklingError: Can't pickle class 
'Products.CMFNauTools.Explorer.FolderExplorer': it's not the same object as 
Products.CMFNauTools.Explorer.FolderExplorer

previous Zope version, which I used, was 2.6.1, but it was very old version and
I  decided to jump to 2.8.0. I took problems with autorefresh. What can I do to 
solve
my problems?

p.s. sorry for my english.

-- 
Best regards,
 Victor Safronovichmailto:[EMAIL PROTECTED]
 NauMen.NauDoc.SoftwareDeveloper  http://www.naumen.com

___
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zodb-dev