[Zope] Z2 CONFLICT Competing writes and synchronization woes

2000-08-31 Thread Sean McGrath

(Google -- which normally does an absolutely stunning job
of directing me to answers to Zope questions -- has
drawn a blank on this one:)

I have an external method that writes stuff to a file.

I want to synchronize access to the file so that
multiple callers can be adding stuff to the file
without problems.

Without any synchronization I get interleaved output
most of the time and occasionally an error message
like this:
"Z2 CONFLICT Competing writes at, /foo"

I tried using the threading module and creating
a Lock object as a global in the external method.
This does not help as each request gets allocated its
own Lock object. I tried Rlock got an error message
I didn't understand and concluded I don't know
what I'm doing:-)

Any pointers to the best way to do synchronization of
access to the filesystem from external methods?

regards,
Sean McGrath





___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




Re: [Zope] Z2 CONFLICT Competing writes and synchronization woes

2000-08-31 Thread Dieter Maurer

Sean McGrath writes:
  I want to synchronize ...
  
  I tried using the threading module and creating
  a Lock object as a global in the external method.
  This does not help as each request gets allocated its
  own Lock object

As you observed, each thread gets its own global namespace
for a file containing an external method.

The namespace of a true Python module, however, is shared
by all threads. Therefore, it is a good place for your
lock.

Do the following (or something along similar lines):

 * create a properly named subpackage in "lib/python/Shared"
   (to avoid name clashes), say "myCompany".

 * create a Python module in "myCompany", say "myLock.py".

 * create your lock in this module, say "Lock"

 * access it in your external method by:

from Shared.myCompany.myLock import Lock



Dieter

___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )