IDict(*v, **kw) | Interactive dictionary for use by the computation server. |
Inheritance diagram for mmf.async.server:
Perspective broker implementation of an asynchronous inspector.
Use this to build a two-process client-server application where the server runs a computation that clients can connect to, inspect, and control.
The server should including the following boilerplate code:
from __future__ import with_statement
...
import server
...
def run_computation(..., idict, ...):
...
while (not idict.terminated and ...): # Allows clients to terminate
idict.wait() # Allows clients to pause
with idict.lock: # Use lock to be threadsafe
idict[...] = ... # Put intermediate results into idict.
...
idict.notify_update() # Call to notify clients of changes.
... <good time to checkpoint>
...
idict.notify_update(final=True) # Notify of final update.
def plot_results(idict):
"Plot intermediate results from idict."
...
def print_mesg(idict):
"Print messages from idict."
...
def run(...):
idict = server.IDict()
idict.callbacks.add(plot_results) # Add these if you want the server
idict.callbacks.add(print_mesg) # to plot and print on updates.
server_controller = server.run_server(idict)
run_computation(..., idict=idict, ...)
server_controller.wait_then_close(timeout=...)
if __name__ = '__main__':2
run()
This sets up a Perspective Broker using twisted that makes the idict available as the root object that clients can connect to and inspect.
Bases: dict, twisted.spread.jelly.Jellyable, twisted.spread.jelly.Unjellyable
Interactive dictionary for use by the computation server.
This dictionary maintains some state relevant for the server, such as a lock, and a set of callbacks. This object is also jellyable and unjellyable so that it can be serialized and sent across the network. If entries in the dictionary cannot be jellied by default, then one will have to modify getStateFor and setStateFor (presently these use pickles, but this is NOT SECURE)
Use the lock as follows
Don’t use the lock when calling functions like notify_update() which use the lock.
Methods
add_callback(callback) | Register the specified callback to receive update notices. |
clear | D.clear() -> None. Remove all items from D. |
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. |
getStateFor(jellier) | Convert self to some jellyable object and return that. |
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 |
jellyFor(jellier) | @see: L{twisted.spread.interfaces.IJellyable.jellyFor} |
keys | D.keys() -> list of D’s keys |
notify_update([final]) | The calculation server should call this whenever it is finished updating. |
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 |
setStateFor(unjellier, state) | Restore from state which was created by getStateFor. |
setdefault | D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D |
terminate() | Ask the computation server to terminate. |
unjellyFor(unjellier, jellyList) | Perform the inverse operation of L{Jellyable.jellyFor}. |
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([timeout]) | Wait if synchronization object is specified. |
Register the specified callback to receive update notices.
Note: this is redundant. Just use self.callbacks.add()