Package commons :: Module async
[hide private]
[frames] | no frames]

Module async

source code

Asynchronous utilities for use with the Twisted library.

Functions [hide private]
defer.Deferred
async_sleep(seconds)
Acts as the asynchronous version of time.sleep.
source code
function
asynchronized(func)
Acts as the asynchronous version of a synchronized decorator (inspired by Java's keyword).
source code
Variables [hide private]
  __package__ = 'commons'
Function Details [hide private]

async_sleep(seconds)

source code 

Acts as the asynchronous version of time.sleep.

Parameters:
  • seconds (float) - The amount of time in seconds to sleep.
Returns: defer.Deferred
The defer.Deferred that will be fired on wake-up.

asynchronized(func)

source code 

Acts as the asynchronous version of a synchronized decorator (inspired by Java's keyword). Ensures that no event-handling path (the asynchronous equivalent to threads) will enter the function if another one is currently in it (which can happen if the current "thread" is itself waiting on a deferred, thus giving the reactor an opportunity to execute the competing "thread").

Provides additional protection against Twisted bug 411. In this case, if too many acquisition requests are chained onto the deferred which is fired on release, then the stack will overflow. This is circumvented by maintaining a queue of closures and deferreds which is checked on each release, to keep the callback chain "flat."

Parameters:
  • func (function) - The function to decorate.
Returns: function
The "thread-safe" version of the function.