def getResult(self, targets, i=None): """Get the stdin/stdout/stderr of a previously executed command on targets. :Parameters: targets : int, list or 'all' The engine ids the action will apply to. Call `getIDs` to see a list of currently available engines. i : None or int The command number to retrieve. The default will retrieve the most recent command. :Returns: The result dict for the command. """ if i is None: # This is because None cannot be marshalled by xml-rpc i = 'None' self._checkClientID() localBlock = self._reallyBlock() result = self._executeRemoteMethod(self._server.getResult, self._clientID, localBlock, targets, i) if not localBlock: result = PendingResult(self, result) result.addCallback(wrapResultList) else: result = ResultList(result) return result
def execute(self, targets, lines, block=None): """Execute lines of code on targets and possibly block. :Parameters: targets : int, list or 'all' The engine ids the action will apply to. Call `get_ids` to see a list of currently available engines. lines : str A string of Python code to execute. block : boolean Should I block or not. If block=True, wait for the action to complete and return the result. If block=False, return a `PendingResult` object that can be used to later get the result. If block is not specified, the block attribute will be used instead. :Returns: A list of dictionaries with the stdin/stdout/stderr of the command on each targets. """ self._checkClientID() localBlock = self._reallyBlock(block) result = self._executeRemoteMethod('execute', targets, clientID=self._clientID, block=localBlock, lines=lines) if not localBlock: result = PendingResult(self, result) result.addCallback(wrapResultList) else: result = ResultList(result) return result
def get_result(self, targets, i=None): """Get the stdin/stdout/stderr of a previously executed command on targets. :Parameters: targets : int, list or 'all' The engine ids the action will apply to. Call `get_ids` to see a list of currently available engines. i : None or int The command number to retrieve. The default will retrieve the most recent command. :Returns: The result dict for the command. """ self._checkClientID() localBlock = self._reallyBlock() result = self._executeRemoteMethod('get_result', targets, clientID=self._clientID, block=localBlock, id=i) if not localBlock: result = PendingResult(self, result) result.addCallback(wrapResultList) else: result = ResultList(result) return result
def has_properties(self, targets, *keys): """check the properties dicts of engines for keys. This method gets the Python objects specified in keys from the engines specified in targets, returning a dict for each engine. :Parameters: targets : int, list or 'all' The engine ids the action will apply to. Call `get_ids` to see a list of currently available engines. keys: list or tuple of str A list of variable names as string of the properties to be checked. :Returns: A list of lists of boolean values for each target. if no keys specified, the whole properties dict is pulled. Examples ======== >> rc.has_propertiesAll('a', 'b') [[True, False],[False, True],[True, True]] """ self._checkClientID() localBlock = self._reallyBlock() result = self._executeRemoteMethod('has_properties', targets, clientID=self._clientID, block=localBlock, keys=keys) if not localBlock: result = PendingResult(self, result) return result
def set_properties(self, targets, **namespace): """Update the properties with key/value pairs. This method takes all key/value pairs passed in as keyword arguments and pushes (sends) them to the engines specified in targets. Simple types are recommended (strings, numbers, etc.). :Parameters: targets : int, list or 'all' The engine ids the action will apply to. Call `get_ids` to see a list of currently available engines. namespace : dict The keyword arguments of that contain the key/value pairs that will be pushed. Examples ======== >>> rc.set_properties('all', a=5) # sets e.properties['a'] = 5 on all >>> rc.set_properties(0, b=30) # sets e.properties['b'] = 30 on 0 """ self._checkClientID() # binPackage = xmlrpc.Binary(pickle.dumps(namespace, 2)) localBlock = self._reallyBlock() result = self._executeRemoteMethod('set_properties', targets, clientID=self._clientID, block=localBlock, namespace=namespace) if not localBlock: result = PendingResult(self, result) return result
def get_properties(self, targets, *keys): """Pull subdicts of properties objects on engines by keys. This method gets the Python objects specified in keys from the engines specified in targets, returning a dict for each engine. :Parameters: targets : int, list or 'all' The engine ids the action will apply to. Call `get_ids` to see a list of currently available engines. keys: list or tuple of str A list of variable names as string of the Python objects to be pulled back to the client. :Returns: A list of dictionary objects for each target. if no keys specified, the whole properties dict is pulled. Examples ======== >> rc.get_propertiesAll('a') [{'a':10},{'a':10},{'a':10}] """ self._checkClientID() localBlock = self._reallyBlock() result = self._executeRemoteMethod('get_properties', targets, clientID=self._clientID, block=localBlock, keys=keys) if not localBlock: result = PendingResult(self, result) return result
def gather(self, targets, key, style='basic'): """Gather a set of sequence partitions that are distributed on targets. This method is the inverse of `scatter` and gather parts of an overall sequence that are distributed among the engines and reassembles the partitions into a single sequence which is returned. :Parameters: targets : int, list or 'all' The engine ids the action will apply to. Call `get_ids` to see a list of currently available engines. key : str The name of the sequences on the engines. style : str Only 'basic' is supported currently. :Returns: The reassembled sequence. """ self._checkClientID() localBlock = self._reallyBlock() result = self._executeRemoteMethod('gather', targets, clientID=self._clientID, block=localBlock, key=key, style=style) if not localBlock: result = PendingResult(self, result) return result
def scatter(self, targets, key, seq, style='basic', flatten=False): """Partition and distribute a sequence to a set of targets/engines. This method partitions a Python sequence and then pushes the partitions to a set of engines. :Parameters: targets : int, list or 'all' The engine ids the action will apply to. Call `get_ids` to see a list of currently available engines. key : str What to call the partitions on the engines. seq : list, tuple or numpy array The sequence to be partitioned and pushed. style : str The style of partitioning to use. Only 'basic' is supported flatten : boolean Should length 1 partitions be flattened to scalars upon pushing. """ self._checkClientID() # bseq = xmlrpc.Binary(pickle.dumps(seq,2)) localBlock = self._reallyBlock() result = self._executeRemoteMethod('scatter', targets, clientID=self._clientID, block=localBlock, key=key, seq=seq, style=style, flatten=flatten) if not localBlock: result = PendingResult(self, result) return result
def push(self, targets, **namespace): """Push Python objects by key to targets. This method takes all key/value pairs passed in as keyword arguments and pushes (sends) them to the engines specified in targets. Most Python objects are pickled, but numpy arrays are send using their raw buffers. :Parameters: targets : int, list or 'all' The engine ids the action will apply to. Call `get_ids` to see a list of currently available engines. namespace : dict The keyword arguments of that contain the key/value pairs that will be pushed. Examples ======== >>> rc.push('all', a=5) # pushes 5 to all engines as 'a' >>> rc.push(0, b=30) # pushes 30 to 0 as 'b' """ self._checkClientID() # binPackage = xmlrpc.Binary(pickle.dumps(namespace, 2)) localBlock = self._reallyBlock() result = self._executeRemoteMethod('push', targets, clientID=self._clientID, block=localBlock, namespace=namespace) if not localBlock: result = PendingResult(self, result) return result
def pull(self, targets, *keys): """Pull Python objects by key from targets. This method gets the Python objects specified in keys from the engines specified in targets. :Parameters: targets : int, list or 'all' The engine ids the action will apply to. Call `get_ids` to see a list of currently available engines. keys: list or tuple of str A list of variable names as string of the Python objects to be pulled back to the client. :Returns: A list of pulled Python objects for each target. Examples ======== >> rc.pullAll('a') [10,10,10,10] """ self._checkClientID() localBlock = self._reallyBlock() result = self._executeRemoteMethod('pull', targets, clientID=self._clientID, block=localBlock, keys=keys) if not localBlock: result = PendingResult(self, result) return result
def clear_properties(self, targets): """clear the properties objects on engines. :Parameters: targets : int, list or 'all' The engine ids the action will apply to. Call `get_ids` to see a list of currently available engines. :Returns: None for each engine Examples ======== >> rc.clear_propertiesAll() [None, None, None] >> rc.get_propertiesAll() [{}, {}, {}] """ self._checkClientID() localBlock = self._reallyBlock() result = self._executeRemoteMethod('clear_properties', targets, clientID=self._clientID, block=localBlock) if not localBlock: result = PendingResult(self, result) return result
def del_properties(self, targets, *keys): """remove elements from properties objects on engines by keys. :Parameters: targets : int, list or 'all' The engine ids the action will apply to. Call `get_ids` to see a list of currently available engines. keys: list or tuple of str A list of property labels to be cleared :Returns: None Examples ======== >> rc.del_propertiesAll('a') [None, None] """ self._checkClientID() localBlock = self._reallyBlock() result = self._executeRemoteMethod('del_properties', targets, clientID=self._clientID, block=localBlock, keys=keys) if not localBlock: result = PendingResult(self, result) return result
def clearProperties(self, targets): """Clear properties from targets""" self._checkClientID() localBlock = self._reallyBlock() result = self._executeRemoteMethod(self._server.clearProperties, self._clientID, localBlock, targets) if not localBlock: result = PendingResult(self, result) return result
def processPullResult(rawResult): result = pickle.loads(rawResult.data) if isinstance(result, failure.Failure): result.raiseException() else: if not localBlock: return PendingResult(self, result) else: return result
def getProperties(self, targets, *keys): """Get properties from targets by keys, defaulting to all""" self._checkClientID() localBlock = self._reallyBlock() result = self._executeRemoteMethod(self._server.getProperties, self._clientID, localBlock, targets, *keys) if not localBlock: result = PendingResult(self, result) return result
def delProperties(self, targets, *keys): """Delete properties from targets by keys""" self._checkClientID() localBlock = self._reallyBlock() result = self._executeRemoteMethod(self._server.delProperties, self._clientID, localBlock, targets, *keys) if not localBlock: result = PendingResult(self, result) return result
def setProperties(self, targets, **properties): """Set properties on targets by key/value""" self._checkClientID() binPackage = xmlrpc.Binary(pickle.dumps(properties, 2)) localBlock = self._reallyBlock() result = self._executeRemoteMethod(self._server.setProperties, self._clientID, localBlock, targets, binPackage) if not localBlock: result = PendingResult(self, result) return result
def processPullResult(rawResult): result = pickle.loads(rawResult.data) if isinstance(result, failure.Failure): result.raiseException() else: if not localBlock: return PendingResult(self, result) else: if len(keys) == 1: uncannedResult = [ uncan(r, userGlobals) for r in result ] elif len(keys) > 1: uncannedResult = [ uncanSequence(r, userGlobals) for r in result ] return uncannedResult
def keys(self, targets): """List all the variable names defined on each target. :Parameters: targets : int, list or 'all' The engine ids the action will apply to. Call `getIDs` to see a list of currently available engines. :Returns: A list of the variables names on each engine. """ self._checkClientID() localBlock = self._reallyBlock() result = self._executeRemoteMethod(self._server.keys, self._clientID, localBlock, targets) if not localBlock: result = PendingResult(self, result) return result
def reset(self, targets): """Reset the namespace on targets. This method resets the persistent namespace in which computations are done in the each engine. This is is sort of like a soft reset. Use `kill` to actually stop the engines. :Parameters: targets : int, list or 'all' The engine ids the action will apply to. Call `getIDs` to see a list of currently available engines. """ self._checkClientID() localBlock = self._reallyBlock() result = self._executeRemoteMethod(self._server.reset, self._clientID, localBlock, targets) if not localBlock: result = PendingResult(self, result) return result
def kill(self, targets, controller=False): """Kill the engines/targets specified. This actually stops the engine processes for good. :Parameters: targets : int, list or 'all' The engine ids the action will apply to. Call `getIDs` to see a list of currently available engines. controller : boolean Kill the controller process as well? """ self._checkClientID() localBlock = self._reallyBlock() result = self._executeRemoteMethod(self._server.kill, self._clientID, localBlock, targets, controller) if not localBlock: result = PendingResult(self, result) return result
def pushFunction(self, targets, **namespace): """Push Python functions by key to targets. :Parameters: targets : int, list or 'all' The engine ids the action will apply to. Call `getIDs` to see a list of currently available engines. namespace : dict The keyword arguments of that contain the key/value pairs that will be pushed. """ self._checkClientID() cannedNamespace = canDict(namespace) binPackage = xmlrpc.Binary(pickle.dumps(cannedNamespace, 2)) localBlock = self._reallyBlock() result = self._executeRemoteMethod(self._server.pushFunction, self._clientID, localBlock, targets, binPackage) if not localBlock: result = PendingResult(self, result) return result