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:

def sync_in_progress(busy=None):
    global BUSY_STATE
    if busy is None:
        return BUSY_STATE
        BUSY_STATE = busy

The idea is that BUSY_STATE is a global value shared between all threads, and if the sync_test() function below is called while it is allready running in another thread, it will just return 'Sync allready in progress'.

I then wrap the actual sync code like this:

def long_test_function(): # just to kill time
    t = Timer('Loop time')
    for i in xrange(10**7):
        d = 7*8
        e = 7*8
    print t.time()
    return d

def sync_test(self):
    if not sync_in_progress():
        long_test_function() # placeholder for the real sync code
        return 'Sync done'
        return 'Sync allready in progress'

But it seems that the new method merely waits until the first one has completed.

So it allways returns 'Sync done' and calls long_test_function()

What am I misunderstanding here? Isn't it the right way to share global data? Or is there some kind of locking going on under my nose that I am to blind to see.


hilsen/regards Max M, Denmark

IT's Mad Science

Zope maillist  -  Zope@zope.org
**   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