(Mon, Jun 27, 2005 at 12:00:08PM -0400) [EMAIL PROTECTED] wrote/schrieb/egrapse:
> Message: 9
> Date: Mon, 27 Jun 2005 15:53:38 +0200
> From: Max M <[EMAIL PROTECTED]>
> Subject: [Zope] Sharing global data between threads / locking a method
> To: zope@zope.org
> Message-ID: <[EMAIL PROTECTED]>
> 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

_______________________________________________
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )

Reply via email to