From 300224031ca57efc66e1ae62db764ef27441ef2c Mon Sep 17 00:00:00 2001 From: dhirschf Date: Sun, 7 Oct 2018 13:44:45 +1000 Subject: [PATCH 1/3] Expand description of running async functions with Client.sync --- docs/source/asynchronous.rst | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/source/asynchronous.rst b/docs/source/asynchronous.rst index 1c079035722..1669dd45b99 100644 --- a/docs/source/asynchronous.rst +++ b/docs/source/asynchronous.rst @@ -107,6 +107,23 @@ Python 3 with Tornado from tornado.ioloop import IOLoop IOLoop().run_sync(f) +If you want to reuse an externally created client you need to run the async +function using the clients loop which can be done with the ``Client.sync`` +function - e.g. + +.. code-block:: python + + from dask.distributed import Client + + client = Client() + + async def f(): + future = client.submit(lambda x: x + 1, 10) + return await client.gather(future, asynchronous=True) + + client.sync(f) + + Python 2/3 with Tornado +++++++++++++++++++++++ From 13e005e351480e0f07e5022ba4e4d451b580f642 Mon Sep 17 00:00:00 2001 From: dhirschf Date: Sun, 7 Oct 2018 13:45:26 +1000 Subject: [PATCH 2/3] Add vscode folder to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 7888407d33f..4d2745ad7c8 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,6 @@ continuous_integration/hdfs-initialized .cache .#* .idea/ +.vscode/ .pytest_cache/ dask-worker-space/ From 63659087b24ead69b33966dad6ca62219093ddac Mon Sep 17 00:00:00 2001 From: James Bourbeau Date: Thu, 7 Nov 2019 13:57:03 -0600 Subject: [PATCH 3/3] Fixups [skip ci] --- docs/source/asynchronous.rst | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/docs/source/asynchronous.rst b/docs/source/asynchronous.rst index 7ab2d172448..a49788e1fbe 100644 --- a/docs/source/asynchronous.rst +++ b/docs/source/asynchronous.rst @@ -58,13 +58,12 @@ function to run the asynchronous function: async def f(): future = client.submit(lambda x: x + 1, 10) - results = await client.gather(futures, asynchronous=True) - return results + result = await client.gather(future, asynchronous=True) + return result client.sync(f) - Python 2 Compatibility ---------------------- @@ -101,7 +100,6 @@ Python 3 with Tornado or Asyncio asyncio.get_event_loop().run_until_complete(f()) - Python 2/3 with Tornado +++++++++++++++++++++++