uWSGI unique timer python decorator
Question: I would like to run a cron-like command with python decorators that needs to
be unique (so that if the previous process is still running it doesn't start a
new process) with uwsgi.

taking a look at the documentation (<http://uwsgi-
docs.readthedocs.org/en/latest/PythonDecorators.html>) i saw that i can do
something like this

task.py

    
    
    from uwsgidecorators import *
    
    @timer(600)   #every 10 minutes
    def myfunction(signum):
        pass
    

uwsgi.ini

    
    
    [uwsgi]
    ...
    import=task
    ...
    

but this way it is not unique like if i do something like this (following the
documentation <http://uwsgi-docs.readthedocs.org/en/latest/Cron.html>)

task.py

    
    
    ...
    all_my_tasks
    ...
    

uwsgi.ini

    
    
    [uwsgi]
    ...
    cron2 = minute=-10,unique=1 python path/to/task.py
    ...
    

Isn't there a way to do this using uwsgi's decorators and timer instead of
cron?


Answer: Use the uWSGI locking api:

    
    
       from uwsgidecorators import *
    
       @timer(600)   #every 10 minutes
       def myfunction(signum):
           if uwsgi.is_locked(): return
           uwsgi.lock()
           ....
           uwsgi.unlock()
    

<http://uwsgi-docs.readthedocs.org/en/latest/Locks.html>

