/usr/share/doc/python-distributed-doc/html/_modules/distributed/asyncio.html is in python-distributed-doc 1.20.2+ds.1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 | <!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>distributed.asyncio — Dask.distributed 0+unknown documentation</title>
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<link rel="index" title="Index"
href="../../genindex.html"/>
<link rel="search" title="Search" href="../../search.html"/>
<link rel="top" title="Dask.distributed 0+unknown documentation" href="../../index.html"/>
<link rel="up" title="Module code" href="../index.html"/>
<script src="../../_static/js/modernizr.min.js"></script>
</head>
<body class="wy-body-for-nav" role="document">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search">
<a href="../../index.html" class="icon icon-home"> Dask.distributed
</a>
<div class="version">
0+unknown
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<p class="caption"><span class="caption-text">Getting Started</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../install.html">Install Dask.Distributed</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../quickstart.html">Quickstart</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../setup.html">Setup Network</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../client.html">Client</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../api.html">API</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../faq.html">Frequently Asked Questions</a></li>
</ul>
<p class="caption"><span class="caption-text">Build Understanding</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../diagnosing-performance.html">Diagnosing Performance</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../efficiency.html">Efficiency</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../limitations.html">Limitations</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../locality.html">Data Locality</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../manage-computation.html">Managing Computation</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../memory.html">Managing Memory</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../related-work.html">Related Work</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../resilience.html">Resilience</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../scheduling-policies.html">Scheduling Policies</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../scheduling-state.html">Scheduling State</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../worker.html">Worker</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../work-stealing.html">Work Stealing</a></li>
</ul>
<p class="caption"><span class="caption-text">Additional Features</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../adaptive.html">Adaptive Deployments</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../asynchronous.html">Asynchronous Operation</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../configuration.html">Configuration</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../ec2.html">EC2 Startup Script</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../local-cluster.html">Local Cluster</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../ipython.html">IPython Integration</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../joblib.html">Joblib Integration</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../publish.html">Publish Datasets</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../queues.html">Data Streams with Queues</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../resources.html">Worker Resources</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../submitting-applications.html">Submitting Applications</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../task-launch.html">Launch Tasks from Tasks</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../tls.html">TLS/SSL</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../web.html">Web Interface</a></li>
</ul>
<p class="caption"><span class="caption-text">Developer Documentation</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../changelog.html">Changelog</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../communications.html">Communications</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../develop.html">Development Guidelines</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../foundations.html">Foundations</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../journey.html">Journey of a Task</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../protocol.html">Protocol</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../serialization.html">Custom Serialization</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../plugins.html">Scheduler Plugins</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" role="navigation" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">Dask.distributed</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html">Docs</a> »</li>
<li><a href="../index.html">Module code</a> »</li>
<li>distributed.asyncio</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for distributed.asyncio</h1><div class="highlight"><pre>
<span></span><span class="sd">"""Experimental interface for asyncio, may disappear without warning"""</span>
<span class="c1"># flake8: noqa</span>
<span class="kn">import</span> <span class="nn">asyncio</span>
<span class="kn">from</span> <span class="nn">functools</span> <span class="k">import</span> <span class="n">wraps</span>
<span class="kn">from</span> <span class="nn">toolz</span> <span class="k">import</span> <span class="n">merge</span>
<span class="kn">from</span> <span class="nn">tornado.platform.asyncio</span> <span class="k">import</span> <span class="n">BaseAsyncIOLoop</span>
<span class="kn">from</span> <span class="nn">tornado.platform.asyncio</span> <span class="k">import</span> <span class="n">to_asyncio_future</span>
<span class="kn">from</span> <span class="nn">.</span> <span class="k">import</span> <span class="n">client</span>
<span class="kn">from</span> <span class="nn">.client</span> <span class="k">import</span> <span class="n">Client</span><span class="p">,</span> <span class="n">Future</span>
<span class="kn">from</span> <span class="nn">.variable</span> <span class="k">import</span> <span class="n">Variable</span>
<span class="kn">from</span> <span class="nn">.utils</span> <span class="k">import</span> <span class="n">ignoring</span>
<span class="k">def</span> <span class="nf">to_asyncio</span><span class="p">(</span><span class="n">fn</span><span class="p">,</span> <span class="o">**</span><span class="n">default_kwargs</span><span class="p">):</span>
<span class="sd">"""Converts Tornado gen.coroutines and futures to asyncio ones"""</span>
<span class="nd">@wraps</span><span class="p">(</span><span class="n">fn</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">convert</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="k">if</span> <span class="n">default_kwargs</span><span class="p">:</span>
<span class="n">kwargs</span> <span class="o">=</span> <span class="n">merge</span><span class="p">(</span><span class="n">default_kwargs</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">)</span>
<span class="k">return</span> <span class="n">to_asyncio_future</span><span class="p">(</span><span class="n">fn</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">))</span>
<span class="k">return</span> <span class="n">convert</span>
<div class="viewcode-block" id="AioClient"><a class="viewcode-back" href="../../api.html#distributed.asyncio.AioClient">[docs]</a><span class="k">class</span> <span class="nc">AioClient</span><span class="p">(</span><span class="n">Client</span><span class="p">):</span>
<span class="sd">""" Connect to and drive computation on a distributed Dask cluster</span>
<span class="sd"> This class provides an asyncio compatible async/await interface for</span>
<span class="sd"> dask.distributed.</span>
<span class="sd"> The Client connects users to a dask.distributed compute cluster. It</span>
<span class="sd"> provides an asynchronous user interface around functions and futures.</span>
<span class="sd"> This class resembles executors in ``concurrent.futures`` but also</span>
<span class="sd"> allows ``Future`` objects within ``submit/map`` calls.</span>
<span class="sd"> AioClient is an **experimental** interface for distributed and may</span>
<span class="sd"> disappear without warning!</span>
<span class="sd"> Parameters</span>
<span class="sd"> ----------</span>
<span class="sd"> address: string, or Cluster</span>
<span class="sd"> This can be the address of a ``Scheduler`` server like a string</span>
<span class="sd"> ``'127.0.0.1:8786'`` or a cluster object like ``LocalCluster()``</span>
<span class="sd"> Examples</span>
<span class="sd"> --------</span>
<span class="sd"> Provide cluster's scheduler address on initialization::</span>
<span class="sd"> client = AioClient('127.0.0.1:8786')</span>
<span class="sd"> Start the client::</span>
<span class="sd"> async def start_the_client():</span>
<span class="sd"> client = await AioClient()</span>
<span class="sd"> # Use the client....</span>
<span class="sd"> await client.close()</span>
<span class="sd"> An ``async with`` statement is a more convenient way to start and shut down</span>
<span class="sd"> the client::</span>
<span class="sd"> async def start_the_client():</span>
<span class="sd"> async with AioClient() as client:</span>
<span class="sd"> # Use the client within this block.</span>
<span class="sd"> pass</span>
<span class="sd"> Use the ``submit`` method to send individual computations to the cluster,</span>
<span class="sd"> and await the returned future to retrieve the result::</span>
<span class="sd"> async def add_two_numbers():</span>
<span class="sd"> async with AioClient() as client:</span>
<span class="sd"> a = client.submit(add, 1, 2)</span>
<span class="sd"> result = await a</span>
<span class="sd"> Continue using submit or map on results to build up larger computations,</span>
<span class="sd"> and gather results with the ``gather`` method::</span>
<span class="sd"> async def gather_some_results():</span>
<span class="sd"> async with AioClient() as client:</span>
<span class="sd"> a = client.submit(add, 1, 2)</span>
<span class="sd"> b = client.submit(add, 10, 20)</span>
<span class="sd"> c = client.submit(add, a, b)</span>
<span class="sd"> result = await client.gather([c])</span>
<span class="sd"> See Also</span>
<span class="sd"> --------</span>
<span class="sd"> distributed.client.Client: Blocking Client</span>
<span class="sd"> distributed.scheduler.Scheduler: Internal scheduler</span>
<span class="sd"> """</span>
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">loop</span> <span class="o">=</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">get_event_loop</span><span class="p">()</span>
<span class="n">ioloop</span> <span class="o">=</span> <span class="n">BaseAsyncIOLoop</span><span class="p">(</span><span class="n">loop</span><span class="p">)</span>
<span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="n">loop</span><span class="o">=</span><span class="n">ioloop</span><span class="p">,</span> <span class="n">asynchronous</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">__enter__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">"Use AioClient in an 'async with' block, not 'with'"</span><span class="p">)</span>
<span class="k">async</span> <span class="k">def</span> <span class="nf">__aenter__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">await</span> <span class="n">to_asyncio_future</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_started</span><span class="p">)</span>
<span class="k">return</span> <span class="bp">self</span>
<span class="k">async</span> <span class="k">def</span> <span class="nf">__aexit__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="nb">type</span><span class="p">,</span> <span class="n">value</span><span class="p">,</span> <span class="n">traceback</span><span class="p">):</span>
<span class="k">await</span> <span class="n">to_asyncio_future</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_close</span><span class="p">())</span>
<span class="k">def</span> <span class="nf">__await__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="n">to_asyncio_future</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_started</span><span class="p">)</span><span class="o">.</span><span class="fm">__await__</span><span class="p">()</span>
<span class="n">get</span> <span class="o">=</span> <span class="n">to_asyncio</span><span class="p">(</span><span class="n">Client</span><span class="o">.</span><span class="n">get</span><span class="p">,</span> <span class="n">sync</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="n">sync</span> <span class="o">=</span> <span class="n">to_asyncio</span><span class="p">(</span><span class="n">Client</span><span class="o">.</span><span class="n">sync</span><span class="p">)</span>
<span class="n">close</span> <span class="o">=</span> <span class="n">to_asyncio</span><span class="p">(</span><span class="n">Client</span><span class="o">.</span><span class="n">close</span><span class="p">)</span>
<span class="n">shutdown</span> <span class="o">=</span> <span class="n">to_asyncio</span><span class="p">(</span><span class="n">Client</span><span class="o">.</span><span class="n">shutdown</span><span class="p">)</span></div>
<span class="k">class</span> <span class="nc">as_completed</span><span class="p">(</span><span class="n">client</span><span class="o">.</span><span class="n">as_completed</span><span class="p">):</span>
<span class="fm">__anext__</span> <span class="o">=</span> <span class="n">to_asyncio</span><span class="p">(</span><span class="n">client</span><span class="o">.</span><span class="n">as_completed</span><span class="o">.</span><span class="fm">__anext__</span><span class="p">)</span>
<span class="n">wait</span> <span class="o">=</span> <span class="n">to_asyncio</span><span class="p">(</span><span class="n">client</span><span class="o">.</span><span class="n">_wait</span><span class="p">)</span>
</pre></div>
</div>
<div class="articleComments">
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
© Copyright 2017, Anaconda, Inc..
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT:'../../',
VERSION:'0+unknown',
COLLAPSE_INDEX:false,
FILE_SUFFIX:'.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt'
};
</script>
<script type="text/javascript" src="../../_static/jquery.js"></script>
<script type="text/javascript" src="../../_static/underscore.js"></script>
<script type="text/javascript" src="../../_static/doctools.js"></script>
<script type="text/javascript" src="../../_static/js/theme.js"></script>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.StickyNav.enable();
});
</script>
</body>
</html>
|