Previous topic

mmf.async.tst

This Page

mmf.async.twisted_utils

TwistedThread() Python Thread that runs the twisted reactor.
RIDict([host, port]) Implements a remote IDict interface that connects to a
callTwisted(*v, **kw) Decorate a function to be called from twisted.
run_reactor_as_thread()
run_reactor()
stop_reactor()

Inheritance diagram for mmf.async.twisted_utils:

Inheritance diagram of mmf.async.twisted_utils

Some utilities to supplement twisted.

class mmf.async.twisted_utils.TwistedThread[source]

Bases: threading.Thread

Python Thread that runs the twisted reactor.

Methods

getName()
isAlive()
isDaemon()
is_alive()
join([timeout])
run() Run the reactor without signal handlers.
setDaemon(daemonic)
setName(name)
start()
stop() Stop the reactor and join the thread...

Start the thread as a daemon (meaning that it will not block the closing of the process when the main thread executes.

Methods

getName()
isAlive()
isDaemon()
is_alive()
join([timeout])
run() Run the reactor without signal handlers.
setDaemon(daemonic)
setName(name)
start()
stop() Stop the reactor and join the thread...
__init__()[source]

Start the thread as a daemon (meaning that it will not block the closing of the process when the main thread executes.

run()[source]

Run the reactor without signal handlers. (Signals go to the main thread.)

stop()[source]

Stop the reactor and join the thread... i.e. block until the reactor stops.

class mmf.async.twisted_utils.RIDict(host='localhost', port=2728)[source]

Bases: dict

Implements a remote IDict interface that connects to a specified server.

Methods

clear D.clear() -> None. Remove all items from D.
connect() Try to connect to the specified host.
copy D.copy() -> a shallow copy of D
fromkeys(...) v defaults to None.
get D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.
has_key D.has_key(k) -> True if D has a key k, else False
items D.items() -> list of D’s (key, value) pairs, as 2-tuples
iteritems D.iteritems() -> an iterator over the (key, value) items of D
iterkeys D.iterkeys() -> an iterator over the keys of D
itervalues D.itervalues() -> an iterator over the values of D
keys D.keys() -> list of D’s keys
onConnect(protocol)
onFail(failure)
onUpdate(idict)
pop D.pop(k[,d]) -> v, remove specified key and return the corresponding value.
popitem D.popitem() -> (k, v), remove and return some (key, value) pair as a
setdefault D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D
subscribe(*v, **k) Subscribe for update notification from the server.
update D.update(E, **F) -> None. Update D from dict/iterable E and F.
values D.values() -> list of D’s values
viewitems D.viewitems() -> a set-like object providing a view on D’s items
viewkeys D.viewkeys() -> a set-like object providing a view on D’s keys
viewvalues D.viewvalues() -> an object providing a view on D’s values
wait_for_update([timeout]) Block until an update is received.
__init__(host='localhost', port=2728)[source]
connect()[source]

Try to connect to the specified host.

onConnect(protocol)[source]
onFail(failure)[source]
onUpdate(idict)[source]
subscribe(*v, **k)[source]

Subscribe for update notification from the server.

skip: Skip this many updates. delay: Minimum time delay between updates. (Could be longer

if the sever does not have any updates.)
wait_for_update(timeout=None)[source]

Block until an update is received.

mmf.async.twisted_utils.callTwisted(*v, **kw)[source]

Decorate a function to be called from twisted. The function is expected to return a value, not a deferred.

The function will do several things: 1) If the twisted reactor is not running, it will register itself

to be run at the startup and then will return a deferred.
  1. If the twisted reactor is running from the current thread, it calls the reactor (possibly with a delay).
  2. If the twisted reactor is running from another thread, it calls the reactor using the callFromThread method.

Parameters: delay: Delay the call (only if block is False and the reactor is

running).
block: If True and the reactor is running, then this will block
and return the result of the function, otherwise it will return a deferred.

If you are going to call something that the twisted reactor needs to deal with, you should decorate with this. This will ensure that if the current thread is not the reactor thread, then the function will be called with reactor.callFromThread. Examples include calls to:

  • transport.write()
  • transport.loseConnection()
mmf.async.twisted_utils.run_reactor_as_thread()[source]
mmf.async.twisted_utils.run_reactor()[source]
mmf.async.twisted_utils.stop_reactor()[source]