b3j0f.annotation.async module

Decorators dedicated to asynchronous programming.

class b3j0f.annotation.async.Synchronized(lock=None, *args, **kwargs)[source]

Bases: b3j0f.annotation.interception.PrivateInterceptor

Transform a target into a thread safe target.

enable
interception
override
propagate
targets
class b3j0f.annotation.async.SynchronizedClass(lock=None, *args, **kwargs)[source]

Bases: b3j0f.annotation.async.Synchronized

Transform a class into a thread safe class.

on_bind_target(target, ctx=None)[source]
class b3j0f.annotation.async.Asynchronous(*args, **kwargs)[source]

Bases: b3j0f.annotation.core.Annotation

Transform a target into an asynchronous callable target.

exception NotYetDoneException[source]

Bases: exceptions.Exception

Handle when a result is not yet available.

class Asynchronous.Result(queue, thread)[source]

Bases: object

In charge of receive asynchronous function result.

get_result(wait=-1)[source]

Get result value.

Wait for it if necessary.

Parameters:wait (int) – maximum wait time.
Returns:result value.
is_done()[source]

True if result is available.

queue
result
thread
Asynchronous.on_bind_target(target, ctx=None)[source]
Asynchronous.start(*args, **kwargs)[source]

Start execution of the function.

class b3j0f.annotation.async.TimeOut(seconds, error_message='Call of {0} with parameters {1} and {2} is timed out in frame {3}', *args, **kwargs)[source]

Bases: b3j0f.annotation.interception.PrivateInterceptor

Raise an Exception if the target call has not finished in time.

ERROR_MESSAGE = 'error_message'
SECONDS = 'seconds'
exception TimeOutError(timeout_interceptor, frame)[source]

Bases: exceptions.Exception

Exception thrown if time elapsed before the end of the target call.

DEFAULT_MESSAGE = 'Call of {0} with parameters {1} and {2} is timed out in frame {3}'

Default time out error message.

TimeOut.enable
TimeOut.error_message
TimeOut.interception
TimeOut.override
TimeOut.propagate
TimeOut.seconds
TimeOut.targets
class b3j0f.annotation.async.Wait(before=1, after=1, *args, **kwargs)[source]

Bases: b3j0f.annotation.interception.PrivateInterceptor

Define a time to wait before and after a target call.

AFTER = 'after'

after attribute name.

BEFORE = 'before'

before attribute name.

DEFAULT_AFTER = 1

default seconds to wait after the target call.

DEFAULT_BEFORE = 1

default seconds to wait before the target call.

after
before
enable
interception
override
propagate
targets
class b3j0f.annotation.async.Observable(*args, **kwargs)[source]

Bases: b3j0f.annotation.interception.PrivateInterceptor

Imlementation of the observer design pattern.

It transforms a target into an observable object in adding method register_observer, unregister_observer and notify_observers. Observers listen to pre/post target interception.

notify_observers(joinpoint, post=False)[source]

Notify observers with parameter calls and information about pre/post call.

on_bind_target(target, ctx=None)[source]
register_observer(observer)[source]

Register an observer.

unregister_observer(observer)[source]

Unregister an observer.