def from_graph()

in pythonflow/pfmq/worker.py [0:0]


    def from_graph(cls, graph, *args, **kwargs):
        """
        Construct a worker from a computational graph.

        Parameters
        ----------
        graph : Graph
            A computational graph.
        """
        def _target(request):
            if 'context' in request:
                return graph(request['fetches'], request['context'])
            if 'contexts' in request:
                return [graph(request['fetches'], context) for context in request['contexts']]
            raise KeyError("`context` or `contexts` must be in the request")

        return cls(_target, *args, **kwargs)