[Zope-dev] FW: Zope & optimistic transactions.
Clark OBrien
COBrien@isis-server.vuse.vanderbilt.edu
Fri, 30 Nov 2001 11:51:51 -0600
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_000_01C179C7.B0C248E0
Content-Type: text/plain;
charset="iso-8859-1"
[Clark OBrien] I think I was sending to zope-dev@zope.COM my mistake- but
an easy one to make.
> From: Clark OBrien
> Sent: Monday, November 05, 2001 7:14 AM
> To: 'chrism@zope.com'; 'k_vertigo@yahoo.com'
> Cc: 'zope@zope.org'
> Subject: Zope & optimistic transactions.
>
>
> Chris,
> I set up a test harness to exercise zopes optimistic transaction
> management.
> My test immediatly caused a ZODB exception.
>
> I am running zope 2.42. on win 2k, the scripts are attached.
> Results below:
>
> As you recall I posed the following question:
>
> What if you had a directory structure like:
> Folder1
> Folder-2
> Folder-3
> ...
> ..
> Folder-n
> Each folder had an attribute foo and there were two scripts, script1 and
> script2.
> script1 modified foo on one Folder only while script2 traversed all the
> folders modifying the attribute foo on each one of them.
> Would the script2 ever commit while the fist while script1 was
> continuously called. This is interesting because a call to script2 would
> never finish before several calls to script1 finished.
>
> I set up a simple test with only 10 folders. I then wrote the script below
> changeLevel2 that is my scri1 above and changeFolders that is my script2
> above.
> I ran changeLevel2 in a loop using the following code:
> ----------------------------------------script----------------------------
> -------------------
> import urllib
> params = urllib.urlencode({'theText': 'Vitamin D'})
> while 1:
> f = urllib.urlopen("http://localhost:8080/Test/changeLevel2?%s" % params)
> print f.read()
> -----------------------------------------script---------------------------
> ---------------------
>
>
> I then ran the script changeFolders from my browsers.
> The result was the following error message:
>
> ------------------------------------------------------------
> ZODB.POSException.ConflictError
>
> Sorry, a site error occurred.
>
> Traceback (innermost last):
> File C:\zope\lib\python\ZPublisher\Publish.py, line 223, in
> publish_module
> File C:\zope\lib\python\ZPublisher\Publish.py, line 200, in publish
> File C:\zope\lib\python\ZPublisher\Publish.py, line 200, in publish
> File C:\zope\lib\python\ZPublisher\Publish.py, line 200, in publish
> File C:\zope\lib\python\ZPublisher\Publish.py, line 195, in publish
> ----------------------------------------------------------
>
>
>
> <<scripts.txt>>
------_=_NextPart_000_01C179C7.B0C248E0
Content-Type: text/plain;
name="scripts.txt"
Content-Disposition: attachment;
filename="scripts.txt"
-----------------------------changeFolder ------------------------------------------------------
#changeFolder
#params list: theFolder,theText
theFolder.manage_changeProperties({'foo':theText})
----------------------------------end changeFolder-----------------------------------------------
-----------------------------------changeFolders--------------------------------------------------
#changeFolders
#Paramater list: myString
# this method changes the attribute foo on several folders.
newFolder = context.getChild("TestFolder" )
newFolder.manage_changeProperties({'foo':myString})
import string
for i in range(1,10):
newFolder = newFolder.getChild("TestFolder" )
for i in range(1,10):
# lets do something expansive
#for j in range(1,100):
#string.find("its a great day to code python","day")
newFolder.manage_changeProperties({'foo':myString})
return "all properties changed"
----------------------------------------------end changeFolders----------------------------------------
---------------------------------------------changeLevel2------------------------------------------------
#changeLevel2
#paramater list: theText
theFolder = context.getChild("TestFolder" )
context.changeFolder(theFolder,theText)
return 'ok'
---------------------------------------------end changeLevel2--------------------------------------------
---------------------------------------------createFolders-----------------------------------------------
temp = context.manage_addFolder('TestFolder','TestFolder')
newFolder = context.getChild("TestFolder" )
newFolder.manage_addProperty("foo","this is a test string", "string")
for i in range(1,10):
newFolder.manage_addFolder("TestFolder","TestFolder")
newFolder = newFolder.getChild("TestFolder" )
newFolder.manage_addProperty("foo","this is a test string", "string")
--------------------------------------------end createFolders -----------------------------------------------
---------------------------------getChild-------------------------------------------------------------------
#getChild
#param list: child
"""
getChild: Utility function
Returns ObjectManagerItem whose ID matches child parameter.
Context must be ObjectManager.
"""
for (oid, obj) in context.objectItems():
if oid == child:
return obj
else:
return None
----------------------------------------end getChild -----------------------------------------------------
----------------------------------------makeNewFolder-----------------------------------------------------
#makeNewFolder
#param list: root
root.manage_addFolder('TestFolder','TestFolder')
root.manage_addProperty('foo','The world is round only to those who know it',"string")
return root.getChild('TestFolder')
--------------------------------------end makeNewFolder-----------------------------------------------
------_=_NextPart_000_01C179C7.B0C248E0--