[Zope] Sharing global data between threads / locking a method

Sascha Welter zopelist at betabug.ch
Wed Jun 29 05:14:08 EDT 2005


(Mon, Jun 27, 2005 at 12:00:08PM -0400) zope-request at zope.org wrote/schrieb/egrapse:
> Message: 9
> Date: Mon, 27 Jun 2005 15:53:38 +0200
> From: Max M <maxm at mxm.dk>
> Subject: [Zope] Sharing global data between threads / locking a method
> To: zope at zope.org
> Message-ID: <d9ovou$4r6$1 at sea.gmane.org>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
> 
> I have a synkronisation script that I run every 10 minutes via wget from 
> a cron job.
> 
> Sometimes the script runs longer than 10 minutes.
> 
> In that case I would like to return a page to wget, but not run the 
> actual script.
> 
> So in a external method/module I have a function like this:

Excuse me, but I really believe trying to solve this situation within
Zope is getting at it from the wrong side.

It is so much easier to wrap the call to wget in a shell, python, perl, 
whatever script. Then you can use a simple lockfile to see if another
wget is still running in a copy of the script. It will take you 10
minutes and you will have solved the problem (at least for the use case
of wget being run from the same machine).

As for making a lock inside Zope, I have done this with setting a
property:
if treeroot.hasProperty('currently_parsing'):
    treeroot.manage_changeProperties( currently_parsing = True )
else:
    treeroot.manage_addProperty('currently_parsing', True, 'boolean')
get_transaction().commit()

For me it never worked inside the SESSION object (for my use case it
does not matter that the session will do the locking only per user).
After I'm done, I do:
treeroot.manage_changeProperties( currently_parsing = False )
get_transaction().commit()

I don't know if this is the proper or cleanest way to do it, but 
It Works(TM).

Regards,

Sascha



More information about the Zope mailing list