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.

**Edit:**

I just realized my actual question is, when start a web2py app, how to init a variable, which will be only inited when the first time web2py starts. Then the sessions / uses can update the variable value. I found the problem of my code is, every time the page is loaded, it will reset the value to multiprocessing.cpu\_count() - 1, even if I store the data to the database, it will be the same result.