/usr/share/doc/python-eventlet-doc/html/threading.html is in python-eventlet-doc 0.20.0-4.
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 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Threads — Eventlet 0.20.0 documentation</title>
<link rel="stylesheet" href="_static/classic.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '0.20.0',
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>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Zeromq" href="zeromq.html" />
<link rel="prev" title="Using SSL With Eventlet" href="ssl.html" />
</head>
<body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="zeromq.html" title="Zeromq"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="ssl.html" title="Using SSL With Eventlet"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="threads">
<h1>Threads<a class="headerlink" href="#threads" title="Permalink to this headline">¶</a></h1>
<p>Eventlet is thread-safe and can be used in conjunction with normal Python threads. The way this works is that coroutines are confined to their ‘parent’ Python thread. It’s like each thread contains its own little world of coroutines that can switch between themselves but not between coroutines in other threads.</p>
<img alt="_images/threading_illustration.png" src="_images/threading_illustration.png" />
<p>You can only communicate cross-thread using the “real” thread primitives and pipes. Fortunately, there’s little reason to use threads for concurrency when you’re already using coroutines.</p>
<p>The vast majority of the times you’ll want to use threads are to wrap some operation that is not “green”, such as a C library that uses its own OS calls to do socket operations. The <a class="reference internal" href="#module-eventlet.tpool" title="eventlet.tpool"><code class="xref py py-mod docutils literal"><span class="pre">tpool</span></code></a> module is provided to make these uses simpler.</p>
<p>The optional <a class="reference internal" href="hubs.html#understanding-hubs"><span class="std std-ref">pyevent hub</span></a> is not compatible with threads.</p>
<div class="section" id="tpool-simple-thread-pool">
<h2>Tpool - Simple thread pool<a class="headerlink" href="#tpool-simple-thread-pool" title="Permalink to this headline">¶</a></h2>
<p>The simplest thing to do with <a class="reference internal" href="#module-eventlet.tpool" title="eventlet.tpool"><code class="xref py py-mod docutils literal"><span class="pre">tpool</span></code></a> is to <a class="reference internal" href="#eventlet.tpool.execute" title="eventlet.tpool.execute"><code class="xref py py-func docutils literal"><span class="pre">execute()</span></code></a> a function with it. The function will be run in a random thread in the pool, while the calling coroutine blocks on its completion:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">thread</span>
<span class="gp">>>> </span><span class="kn">from</span> <span class="nn">eventlet</span> <span class="k">import</span> <span class="n">tpool</span>
<span class="gp">>>> </span><span class="k">def</span> <span class="nf">my_func</span><span class="p">(</span><span class="n">starting_ident</span><span class="p">):</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="s2">"running in new thread:"</span><span class="p">,</span> <span class="n">starting_ident</span> <span class="o">!=</span> <span class="n">thread</span><span class="o">.</span><span class="n">get_ident</span><span class="p">())</span>
<span class="gp">...</span>
<span class="gp">>>> </span><span class="n">tpool</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="n">my_func</span><span class="p">,</span> <span class="n">thread</span><span class="o">.</span><span class="n">get_ident</span><span class="p">())</span>
<span class="go">running in new thread: True</span>
</pre></div>
</div>
<p>By default there are 20 threads in the pool, but you can configure this by setting the environment variable <code class="docutils literal"><span class="pre">EVENTLET_THREADPOOL_SIZE</span></code> to the desired pool size before importing tpool.</p>
<span class="target" id="module-eventlet.tpool"></span><dl class="function">
<dt id="eventlet.tpool.execute">
<code class="descclassname">eventlet.tpool.</code><code class="descname">execute</code><span class="sig-paren">(</span><em>meth</em>, <em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#eventlet.tpool.execute" title="Permalink to this definition">¶</a></dt>
<dd><p>Execute <em>meth</em> in a Python thread, blocking the current coroutine/
greenthread until the method completes.</p>
<p>The primary use case for this is to wrap an object or module that is not
amenable to monkeypatching or any of the other tricks that Eventlet uses
to achieve cooperative yielding. With tpool, you can force such objects to
cooperate with green threads by sticking them in native threads, at the cost
of some overhead.</p>
</dd></dl>
<dl class="class">
<dt id="eventlet.tpool.Proxy">
<em class="property">class </em><code class="descclassname">eventlet.tpool.</code><code class="descname">Proxy</code><span class="sig-paren">(</span><em>obj</em>, <em>autowrap=()</em>, <em>autowrap_names=()</em><span class="sig-paren">)</span><a class="headerlink" href="#eventlet.tpool.Proxy" title="Permalink to this definition">¶</a></dt>
<dd><p>a simple proxy-wrapper of any object that comes with a
methods-only interface, in order to forward every method
invocation onto a thread in the native-thread pool. A key
restriction is that the object’s methods should not switch
greenlets or use Eventlet primitives, since they are in a
different thread from the main hub, and therefore might behave
unexpectedly. This is for running native-threaded code
only.</p>
<p>It’s common to want to have some of the attributes or return
values also wrapped in Proxy objects (for example, database
connection objects produce cursor objects which also should be
wrapped in Proxy objects to remain nonblocking). <em>autowrap</em>, if
supplied, is a collection of types; if an attribute or return
value matches one of those types (via isinstance), it will be
wrapped in a Proxy. <em>autowrap_names</em> is a collection
of strings, which represent the names of attributes that should be
wrapped in Proxy objects when accessed.</p>
</dd></dl>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Threads</a><ul>
<li><a class="reference internal" href="#tpool-simple-thread-pool">Tpool - Simple thread pool</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="ssl.html"
title="previous chapter">Using SSL With Eventlet</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="zeromq.html"
title="next chapter">Zeromq</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/threading.rst.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<div><input type="text" name="q" /></div>
<div><input type="submit" value="Go" /></div>
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="zeromq.html" title="Zeromq"
>next</a> |</li>
<li class="right" >
<a href="ssl.html" title="Using SSL With Eventlet"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> »</li>
</ul>
</div>
<div class="footer" role="contentinfo">
© Copyright 2005-2017, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.6.5.
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-42952223-1', 'eventlet.net');
ga('send', 'pageview');
</script>
</body>
</html>
|