I have a Web2Py webapp which is a web interface for a blastn script. Now I 
need to limit the process running simultaneously, my thought is,

When the webapp starts, the way I did is, in default.py:

    available_worker = multiprocessing.cpu_count() - 1


    def get_workers():
        global available_worker
        return available_worker


    def consume_worker():
        global available_worker
        available_worker = available_worker - 1


    def free_worker():
        global available_worker
        available_worker = available_worker + 1


    def index():
        if get_workers() > 0:
            consume_worker()
            # run a script
            free_worker()
        print get_workers()


Obviously, it will not work as every time the web loads, it resets the 
available_worker to `multiprocessing.cpu_count() - 1`.

I am just wondering, if there is a way I can share the availabe_worker 
across the web sessions or users. 

So by the time a user A loads the page, the `available_worker` is 2, he 
runs the script. While user A is running the script, a user B loads the 
webapp, and he gets `available_worker` is 1, and he runs the script. While 
A and B are running the script, the a user C comes, he gets 
`available_worker` is 0, so he has to wait until either A or B finishes the 
script before he can run the script.

I am new to programming, a detailed explanation and sample code will be 
much much appreciated. 

Thank you.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to