util.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <!DOCTYPE html>
  2. <!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
  3. <!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
  4. <head>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>grpc.framework.base.util &mdash; grpcio 0.11.0b0 documentation</title>
  8. <link rel="stylesheet" href="../../../../_static/css/theme.css" type="text/css" />
  9. <link rel="top" title="grpcio 0.11.0b0 documentation" href="../../../../index.html"/>
  10. <link rel="up" title="Module code" href="../../../index.html"/>
  11. <script src="_static/js/modernizr.min.js"></script>
  12. </head>
  13. <body class="wy-body-for-nav" role="document">
  14. <div class="wy-grid-for-nav">
  15. <nav data-toggle="wy-nav-shift" class="wy-nav-side">
  16. <div class="wy-side-nav-search">
  17. <a href="../../../../index.html" class="icon icon-home"> grpcio
  18. </a>
  19. <div role="search">
  20. <form id="rtd-search-form" class="wy-form" action="../../../../search.html" method="get">
  21. <input type="text" name="q" placeholder="Search docs" />
  22. <input type="hidden" name="check_keywords" value="yes" />
  23. <input type="hidden" name="area" value="default" />
  24. </form>
  25. </div>
  26. </div>
  27. <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
  28. <ul>
  29. <li class="toctree-l1"><a class="reference internal" href="../../../../grpc.html">grpc package</a><ul>
  30. <li class="toctree-l2"><a class="reference internal" href="../../../../grpc.html#subpackages">Subpackages</a><ul>
  31. <li class="toctree-l3"><a class="reference internal" href="../../../../grpc.beta.html">grpc.beta package</a><ul>
  32. <li class="toctree-l4"><a class="reference internal" href="../../../../grpc.beta.html#submodules">Submodules</a></li>
  33. <li class="toctree-l4"><a class="reference internal" href="../../../../grpc.beta.html#module-grpc.beta.implementations">grpc.beta.implementations module</a></li>
  34. <li class="toctree-l4"><a class="reference internal" href="../../../../grpc.beta.html#module-grpc.beta.interfaces">grpc.beta.interfaces module</a></li>
  35. <li class="toctree-l4"><a class="reference internal" href="../../../../grpc.beta.html#module-grpc.beta.utilities">grpc.beta.utilities module</a></li>
  36. <li class="toctree-l4"><a class="reference internal" href="../../../../grpc.beta.html#module-grpc.beta">Module contents</a></li>
  37. </ul>
  38. </li>
  39. <li class="toctree-l3"><a class="reference internal" href="../../../../grpc.early_adopter.html">grpc.early_adopter package</a><ul>
  40. <li class="toctree-l4"><a class="reference internal" href="../../../../grpc.early_adopter.html#submodules">Submodules</a></li>
  41. <li class="toctree-l4"><a class="reference internal" href="../../../../grpc.early_adopter.html#module-grpc.early_adopter.implementations">grpc.early_adopter.implementations module</a></li>
  42. <li class="toctree-l4"><a class="reference internal" href="../../../../grpc.early_adopter.html#module-grpc.early_adopter">Module contents</a></li>
  43. </ul>
  44. </li>
  45. <li class="toctree-l3"><a class="reference internal" href="../../../../grpc.framework.html">grpc.framework package</a><ul>
  46. <li class="toctree-l4"><a class="reference internal" href="../../../../grpc.framework.html#subpackages">Subpackages</a></li>
  47. <li class="toctree-l4"><a class="reference internal" href="../../../../grpc.framework.html#module-grpc.framework">Module contents</a></li>
  48. </ul>
  49. </li>
  50. </ul>
  51. </li>
  52. <li class="toctree-l2"><a class="reference internal" href="../../../../grpc.html#module-grpc">Module contents</a></li>
  53. </ul>
  54. </li>
  55. </ul>
  56. </div>
  57. &nbsp;
  58. </nav>
  59. <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
  60. <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
  61. <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
  62. <a href="../../../../index.html">grpcio</a>
  63. </nav>
  64. <div class="wy-nav-content">
  65. <div class="rst-content">
  66. <div role="navigation" aria-label="breadcrumbs navigation">
  67. <ul class="wy-breadcrumbs">
  68. <li><a href="../../../../index.html">Docs</a> &raquo;</li>
  69. <li><a href="../../../index.html">Module code</a> &raquo;</li>
  70. <li>grpc.framework.base.util</li>
  71. <li class="wy-breadcrumbs-aside">
  72. </li>
  73. </ul>
  74. <hr/>
  75. </div>
  76. <div role="main" class="document">
  77. <h1>Source code for grpc.framework.base.util</h1><div class="highlight"><pre>
  78. <span class="c"># Copyright 2015, Google Inc.</span>
  79. <span class="c"># All rights reserved.</span>
  80. <span class="c">#</span>
  81. <span class="c"># Redistribution and use in source and binary forms, with or without</span>
  82. <span class="c"># modification, are permitted provided that the following conditions are</span>
  83. <span class="c"># met:</span>
  84. <span class="c">#</span>
  85. <span class="c"># * Redistributions of source code must retain the above copyright</span>
  86. <span class="c"># notice, this list of conditions and the following disclaimer.</span>
  87. <span class="c"># * Redistributions in binary form must reproduce the above</span>
  88. <span class="c"># copyright notice, this list of conditions and the following disclaimer</span>
  89. <span class="c"># in the documentation and/or other materials provided with the</span>
  90. <span class="c"># distribution.</span>
  91. <span class="c"># * Neither the name of Google Inc. nor the names of its</span>
  92. <span class="c"># contributors may be used to endorse or promote products derived from</span>
  93. <span class="c"># this software without specific prior written permission.</span>
  94. <span class="c">#</span>
  95. <span class="c"># THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS</span>
  96. <span class="c"># &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT</span>
  97. <span class="c"># LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR</span>
  98. <span class="c"># A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT</span>
  99. <span class="c"># OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,</span>
  100. <span class="c"># SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT</span>
  101. <span class="c"># LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,</span>
  102. <span class="c"># DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY</span>
  103. <span class="c"># THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT</span>
  104. <span class="c"># (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE</span>
  105. <span class="c"># OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span>
  106. <span class="sd">&quot;&quot;&quot;Utilities helpful for working with the base layer of RPC Framework.&quot;&quot;&quot;</span>
  107. <span class="kn">import</span> <span class="nn">collections</span>
  108. <span class="kn">import</span> <span class="nn">threading</span>
  109. <span class="kn">from</span> <span class="nn">grpc.framework.base</span> <span class="kn">import</span> <span class="n">interfaces</span>
  110. <span class="k">class</span> <span class="nc">_ServicedSubscription</span><span class="p">(</span>
  111. <span class="n">collections</span><span class="o">.</span><span class="n">namedtuple</span><span class="p">(</span><span class="s">&#39;_ServicedSubscription&#39;</span><span class="p">,</span> <span class="p">[</span><span class="s">&#39;kind&#39;</span><span class="p">,</span> <span class="s">&#39;ingestor&#39;</span><span class="p">]),</span>
  112. <span class="n">interfaces</span><span class="o">.</span><span class="n">ServicedSubscription</span><span class="p">):</span>
  113. <span class="sd">&quot;&quot;&quot;See interfaces.ServicedSubscription for specification.&quot;&quot;&quot;</span>
  114. <span class="n">_NONE_SUBSCRIPTION</span> <span class="o">=</span> <span class="n">_ServicedSubscription</span><span class="p">(</span>
  115. <span class="n">interfaces</span><span class="o">.</span><span class="n">ServicedSubscription</span><span class="o">.</span><span class="n">Kind</span><span class="o">.</span><span class="n">NONE</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span>
  116. <span class="n">_TERMINATION_ONLY_SUBSCRIPTION</span> <span class="o">=</span> <span class="n">_ServicedSubscription</span><span class="p">(</span>
  117. <span class="n">interfaces</span><span class="o">.</span><span class="n">ServicedSubscription</span><span class="o">.</span><span class="n">Kind</span><span class="o">.</span><span class="n">TERMINATION_ONLY</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span>
  118. <div class="viewcode-block" id="none_serviced_subscription"><a class="viewcode-back" href="../../../../grpc.framework.base.html#grpc.framework.base.util.none_serviced_subscription">[docs]</a><span class="k">def</span> <span class="nf">none_serviced_subscription</span><span class="p">():</span>
  119. <span class="sd">&quot;&quot;&quot;Creates a &quot;none&quot; interfaces.ServicedSubscription object.</span>
  120. <span class="sd"> Returns:</span>
  121. <span class="sd"> An interfaces.ServicedSubscription indicating no subscription to an</span>
  122. <span class="sd"> operation&#39;s results (such as would be the case for a fire-and-forget</span>
  123. <span class="sd"> operation invocation).</span>
  124. <span class="sd"> &quot;&quot;&quot;</span>
  125. <span class="k">return</span> <span class="n">_NONE_SUBSCRIPTION</span>
  126. </div>
  127. <div class="viewcode-block" id="termination_only_serviced_subscription"><a class="viewcode-back" href="../../../../grpc.framework.base.html#grpc.framework.base.util.termination_only_serviced_subscription">[docs]</a><span class="k">def</span> <span class="nf">termination_only_serviced_subscription</span><span class="p">():</span>
  128. <span class="sd">&quot;&quot;&quot;Creates a &quot;termination only&quot; interfaces.ServicedSubscription object.</span>
  129. <span class="sd"> Returns:</span>
  130. <span class="sd"> An interfaces.ServicedSubscription indicating that the front-side customer</span>
  131. <span class="sd"> is interested only in the overall termination outcome of the operation</span>
  132. <span class="sd"> (such as completion or expiration) and would ignore the actual results of</span>
  133. <span class="sd"> the operation.</span>
  134. <span class="sd"> &quot;&quot;&quot;</span>
  135. <span class="k">return</span> <span class="n">_TERMINATION_ONLY_SUBSCRIPTION</span>
  136. </div>
  137. <div class="viewcode-block" id="full_serviced_subscription"><a class="viewcode-back" href="../../../../grpc.framework.base.html#grpc.framework.base.util.full_serviced_subscription">[docs]</a><span class="k">def</span> <span class="nf">full_serviced_subscription</span><span class="p">(</span><span class="n">ingestor</span><span class="p">):</span>
  138. <span class="sd">&quot;&quot;&quot;Creates a &quot;full&quot; interfaces.ServicedSubscription object.</span>
  139. <span class="sd"> Args:</span>
  140. <span class="sd"> ingestor: An interfaces.ServicedIngestor.</span>
  141. <span class="sd"> Returns:</span>
  142. <span class="sd"> An interfaces.ServicedSubscription object indicating a full</span>
  143. <span class="sd"> subscription.</span>
  144. <span class="sd"> &quot;&quot;&quot;</span>
  145. <span class="k">return</span> <span class="n">_ServicedSubscription</span><span class="p">(</span>
  146. <span class="n">interfaces</span><span class="o">.</span><span class="n">ServicedSubscription</span><span class="o">.</span><span class="n">Kind</span><span class="o">.</span><span class="n">FULL</span><span class="p">,</span> <span class="n">ingestor</span><span class="p">)</span>
  147. </div>
  148. <div class="viewcode-block" id="wait_for_idle"><a class="viewcode-back" href="../../../../grpc.framework.base.html#grpc.framework.base.util.wait_for_idle">[docs]</a><span class="k">def</span> <span class="nf">wait_for_idle</span><span class="p">(</span><span class="n">end</span><span class="p">):</span>
  149. <span class="sd">&quot;&quot;&quot;Waits for an interfaces.End to complete all operations.</span>
  150. <span class="sd"> Args:</span>
  151. <span class="sd"> end: Any interfaces.End.</span>
  152. <span class="sd"> &quot;&quot;&quot;</span>
  153. <span class="n">event</span> <span class="o">=</span> <span class="n">threading</span><span class="o">.</span><span class="n">Event</span><span class="p">()</span>
  154. <span class="n">end</span><span class="o">.</span><span class="n">add_idle_action</span><span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">set</span><span class="p">)</span>
  155. <span class="n">event</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span></div>
  156. </pre></div>
  157. </div>
  158. <footer>
  159. <hr/>
  160. <div role="contentinfo">
  161. <p>
  162. &copy; Copyright 2015, Author.
  163. </p>
  164. </div>
  165. 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>.
  166. </footer>
  167. </div>
  168. </div>
  169. </section>
  170. </div>
  171. <script type="text/javascript">
  172. var DOCUMENTATION_OPTIONS = {
  173. URL_ROOT:'../../../../',
  174. VERSION:'0.11.0b0',
  175. COLLAPSE_INDEX:false,
  176. FILE_SUFFIX:'.html',
  177. HAS_SOURCE: true
  178. };
  179. </script>
  180. <script type="text/javascript" src="../../../../_static/jquery.js"></script>
  181. <script type="text/javascript" src="../../../../_static/underscore.js"></script>
  182. <script type="text/javascript" src="../../../../_static/doctools.js"></script>
  183. <script type="text/javascript" src="../../../../_static/js/theme.js"></script>
  184. <script type="text/javascript">
  185. jQuery(function () {
  186. SphinxRtdTheme.StickyNav.enable();
  187. });
  188. </script>
  189. </body>
  190. </html>