示例#1
0
    def test_map_iterates_over_multiple_args(self):
        def map_fn(x, y):
            return x + y

        e = SynchronousExecutor()
        with e.start():
            res = e.wait(e.map(map_fn, [1, 2], [1, 3]))
        assert res == [2, 5]
示例#2
0
    def test_map_doesnt_do_anything_for_empty_list_input(self):
        def map_fn(*args):
            raise ValueError("map_fn was called")

        e = SynchronousExecutor()
        with e.start():
            res = e.wait(e.map(map_fn))
        assert res == []
示例#3
0
    def test_sync_is_depcrecated(self):
        with pytest.warns(UserWarning) as w:
            e = SynchronousExecutor()

        assert "deprecated" in str(w[0].message)
        assert "LocalDaskExecutor" in str(w[0].message)
        assert isinstance(e, LocalDaskExecutor)
        assert e.scheduler == "synchronous"
示例#4
0
def prepare_executor(executor_type, executor_address=None):
    """Instantiate a prefect executor"""
    if executor_type == 'dask':
        if executor_address is not None:
            executor = DaskExecutor(executor_address)
        else:
            executor = DaskExecutor(local_processes=True)
    elif executor_type == "synchronous":
        executor = SynchronousExecutor()
    elif executor_type == 'local':
        executor = LocalExecutor()
    else:
        # Should not happen if click parameters are done correctly, but
        # kept for completeness
        raise ValueError(f'Unknown executor type "{executor_type}".')

    return executor
示例#5
0
 def test_is_pickleable_after_start(self):
     e = SynchronousExecutor()
     with e.start():
         post = cloudpickle.loads(cloudpickle.dumps(e))
         assert isinstance(post, SynchronousExecutor)
示例#6
0
 def test_is_pickleable(self):
     e = SynchronousExecutor()
     post = cloudpickle.loads(cloudpickle.dumps(e))
     assert isinstance(post, SynchronousExecutor)
示例#7
0
 def test_wait(self):
     e = SynchronousExecutor()
     assert e.wait(1) == 1
     assert e.wait(prefect) is prefect
     assert e.wait(e.submit(lambda: 1)) == 1
     assert e.wait(e.submit(lambda x: x, 1)) == 1
     assert e.wait(e.submit(lambda x: x, x=1)) == 1
     assert e.wait(e.submit(lambda: prefect)) is prefect
示例#8
0
 def test_submit(self):
     assert SynchronousExecutor().submit(lambda: 1).compute() == 1
     assert SynchronousExecutor().submit(lambda x: x, 1).compute() == 1
     assert SynchronousExecutor().submit(lambda x: x, x=1).compute() == 1
     assert SynchronousExecutor().submit(
         lambda: prefect).compute() is prefect
示例#9
0
def sync():
    "Synchronous dask (not dask.distributed) executor"
    yield SynchronousExecutor()