util.html 12 KB

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