In [1]:
from IPython.parallel import Client, require

In [2]:
pclient = Client()
dview = pclient[:]
lview = pclient.load_balanced_view()

In [3]:
class doeverywhere(object):
    '''
    Decorator that wraps functions and makes them parallel
    on a particular IPython parallel direct view.
    '''
    
    def __init__(self, view):
        '''
        Takes in a parallel view and caches it internally.
        '''
        self.view = view
    
    def __call__(self, f):
        '''
        Takes in a function and wraps it with another (local) function,
        which applies the function on all workers using the view's
        apply_sync(...) method.
        '''
        
        def wrapper(*args, **kwargs):
            return self.view.apply_sync(f, *args, **kwargs)
        
        return wrapper

In [4]:
def unlist(theinput):
    return theinput[0]

In [5]:
@doeverywhere(dview)
@require(unlist)
def getID(message):
    return message%unlist(a)

In [6]:
dview.scatter('a', pclient.ids)
getID('Worker %d ')


Out[6]:
['Worker 0 ', 'Worker 1 ', 'Worker 2 ', 'Worker 3 ']

In [6]: