Skip to main content

@critsec and @debouncedcritsec for google app engine, python standard environment

Project description

# im_critsec

This library contains the decorator @critsec, for running a function as a critical section (non-reentrant task).

[![Build Status](](

## Install

Use the python package for this library. You can find the package online [here](

Change to your Python App Engine project's root folder and do the following:

> pip install im_critsec --target lib

Or add it to your requirements.txt. You'll also need to set up vendoring, see [app engine vendoring instructions here](

## Usage

You'll need to have im_task set up correctly using either im_task_flask or im_task_webapp (or both!) depending on which framework you are using.

Then, you can run a function as a critical section as follows:

def MyCriticalFunc():
# do some stuff that needs to not be interrupted
# this function will *never* run re-entrantly, even in other processes on other computers

MyCriticalFunc() # kicking off the call to it here.

Critsec forms a separate critical section for each combination of arguments and outer scope references. eg:

def MyCriticalFunc(value):
# do some stuff that needs to not be interrupted
# this function will *never* run re-entrantly, even in other processes on other computers

MyCriticalFunc(1) # first call
MyCriticalFunc(1) # in same critical section as first call
MyCriticalFunc(2) # in a different critical section

## rerun_on_skip

When a critical section is entered, subsequent calls to the same critical section will be ignored while that critical section is running. However, those skipped calls are remembered. Once the critical section is finished, if any calls were skipped, then the critical section runs one more time. This is called rerun_on_skip.

If you would prefer not to have rerun_on_skip, you can turn it off:

@critsec(rerun_on_skip = False)
def ThisFunctionIsNotRerunOnSkip(value):
# do a thing

## @critsec is a form of @task

@critsec is exactly like @task; you can pass in task arguments, eg:

@critsec(queue = "myqueue")
def ThisFunctionRunsOnMyQueue():
# do a thing

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

im_critsec-0.0.4.tar.gz (3.9 kB view hashes)

Uploaded source

Built Distribution

im_critsec-0.0.4-py2.py3-none-any.whl (6.1 kB view hashes)

Uploaded py2 py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page