Website built from v0.20.0-3-gb1d11e3

This commit is contained in:
Sergey Shepelev
2016-12-12 01:37:21 +03:00
parent 588ef1f619
commit d75f9506e5
84 changed files with 6518 additions and 6942 deletions

View File

@@ -31,6 +31,7 @@ auto generated :mod:`pyzmq's <zmq>` from documentation.
:members:
.. autoclass:: zmq.Socket
:members:
.. autoclass:: zmq.Poller
:members:

77
doc/_static/basic.css vendored
View File

@@ -52,6 +52,8 @@ div.sphinxsidebar {
width: 230px;
margin-left: -100%;
font-size: 90%;
word-wrap: break-word;
overflow-wrap : break-word;
}
div.sphinxsidebar ul {
@@ -83,10 +85,6 @@ div.sphinxsidebar #searchbox input[type="text"] {
width: 170px;
}
div.sphinxsidebar #searchbox input[type="submit"] {
width: 30px;
}
img {
border: 0;
max-width: 100%;
@@ -124,6 +122,8 @@ ul.keywordmatches li.goodmatch a {
table.contentstable {
width: 90%;
margin-left: auto;
margin-right: auto;
}
table.contentstable p.biglink {
@@ -151,9 +151,14 @@ table.indextable td {
vertical-align: top;
}
table.indextable dl, table.indextable dd {
table.indextable ul {
margin-top: 0;
margin-bottom: 0;
list-style-type: none;
}
table.indextable > tbody > tr > td > ul {
padding-left: 0em;
}
table.indextable tr.pcap {
@@ -185,8 +190,22 @@ div.genindex-jumpbox {
padding: 0.4em;
}
/* -- domain module index --------------------------------------------------- */
table.modindextable td {
padding: 2px;
border-collapse: collapse;
}
/* -- general body styles --------------------------------------------------- */
div.body p, div.body dd, div.body li, div.body blockquote {
-moz-hyphens: auto;
-ms-hyphens: auto;
-webkit-hyphens: auto;
hyphens: auto;
}
a.headerlink {
visibility: hidden;
}
@@ -212,10 +231,6 @@ div.body td {
text-align: left;
}
.field-list ul {
padding-left: 1em;
}
.first {
margin-top: 0 !important;
}
@@ -332,10 +347,6 @@ table.docutils td, table.docutils th {
border-bottom: 1px solid #aaa;
}
table.field-list td, table.field-list th {
border: 0 !important;
}
table.footnote td, table.footnote th {
border: 0 !important;
}
@@ -372,6 +383,20 @@ div.figure p.caption span.caption-number {
div.figure p.caption span.caption-text {
}
/* -- field list styles ----------------------------------------------------- */
table.field-list td, table.field-list th {
border: 0 !important;
}
.field-list ul {
margin: 0;
padding-left: 1em;
}
.field-list p {
margin: 0;
}
/* -- other body styles ----------------------------------------------------- */
@@ -422,15 +447,6 @@ dl.glossary dt {
font-size: 1.1em;
}
.field-list ul {
margin: 0;
padding-left: 1em;
}
.field-list p {
margin: 0;
}
.optional {
font-size: 1.3em;
}
@@ -489,6 +505,13 @@ pre {
overflow-y: hidden; /* fixes display issues on Chrome browsers */
}
span.pre {
-moz-hyphens: none;
-ms-hyphens: none;
-webkit-hyphens: none;
hyphens: none;
}
td.linenos pre {
padding: 5px 0px;
border: 0;
@@ -580,6 +603,16 @@ span.eqno {
float: right;
}
span.eqno a.headerlink {
position: relative;
left: 0px;
z-index: 1;
}
div.math:hover a.headerlink {
visibility: visible;
}
/* -- printout stylesheet --------------------------------------------------- */
@media print {

View File

@@ -1,8 +1,8 @@
/*
* default.css_t
* classic.css_t
* ~~~~~~~~~~~~~
*
* Sphinx stylesheet -- default theme.
* Sphinx stylesheet -- classic theme.
*
* :copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 756 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 829 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 641 B

View File

@@ -1,256 +1 @@
/*
* default.css_t
* ~~~~~~~~~~~~~
*
* Sphinx stylesheet -- default theme.
*
* :copyright: Copyright 2007-2014 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.
*
*/
@import url("basic.css");
/* -- page layout ----------------------------------------------------------- */
body {
font-family: sans-serif;
font-size: 100%;
background-color: #11303d;
color: #000;
margin: 0;
padding: 0;
}
div.document {
background-color: #1c4e63;
}
div.documentwrapper {
float: left;
width: 100%;
}
div.bodywrapper {
margin: 0 0 0 230px;
}
div.body {
background-color: #ffffff;
color: #000000;
padding: 0 20px 30px 20px;
}
div.footer {
color: #ffffff;
width: 100%;
padding: 9px 0 9px 0;
text-align: center;
font-size: 75%;
}
div.footer a {
color: #ffffff;
text-decoration: underline;
}
div.related {
background-color: #133f52;
line-height: 30px;
color: #ffffff;
}
div.related a {
color: #ffffff;
}
div.sphinxsidebar {
}
div.sphinxsidebar h3 {
font-family: 'Trebuchet MS', sans-serif;
color: #ffffff;
font-size: 1.4em;
font-weight: normal;
margin: 0;
padding: 0;
}
div.sphinxsidebar h3 a {
color: #ffffff;
}
div.sphinxsidebar h4 {
font-family: 'Trebuchet MS', sans-serif;
color: #ffffff;
font-size: 1.3em;
font-weight: normal;
margin: 5px 0 0 0;
padding: 0;
}
div.sphinxsidebar p {
color: #ffffff;
}
div.sphinxsidebar p.topless {
margin: 5px 10px 10px 10px;
}
div.sphinxsidebar ul {
margin: 10px;
padding: 0;
color: #ffffff;
}
div.sphinxsidebar a {
color: #98dbcc;
}
div.sphinxsidebar input {
border: 1px solid #98dbcc;
font-family: sans-serif;
font-size: 1em;
}
/* -- hyperlink styles ------------------------------------------------------ */
a {
color: #355f7c;
text-decoration: none;
}
a:visited {
color: #355f7c;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
/* -- body styles ----------------------------------------------------------- */
div.body h1,
div.body h2,
div.body h3,
div.body h4,
div.body h5,
div.body h6 {
font-family: 'Trebuchet MS', sans-serif;
background-color: #f2f2f2;
font-weight: normal;
color: #20435c;
border-bottom: 1px solid #ccc;
margin: 20px -20px 10px -20px;
padding: 3px 0 3px 10px;
}
div.body h1 { margin-top: 0; font-size: 200%; }
div.body h2 { font-size: 160%; }
div.body h3 { font-size: 140%; }
div.body h4 { font-size: 120%; }
div.body h5 { font-size: 110%; }
div.body h6 { font-size: 100%; }
a.headerlink {
color: #c60f0f;
font-size: 0.8em;
padding: 0 4px 0 4px;
text-decoration: none;
}
a.headerlink:hover {
background-color: #c60f0f;
color: white;
}
div.body p, div.body dd, div.body li {
text-align: justify;
line-height: 130%;
}
div.admonition p.admonition-title + p {
display: inline;
}
div.admonition p {
margin-bottom: 5px;
}
div.admonition pre {
margin-bottom: 5px;
}
div.admonition ul, div.admonition ol {
margin-bottom: 5px;
}
div.note {
background-color: #eee;
border: 1px solid #ccc;
}
div.seealso {
background-color: #ffc;
border: 1px solid #ff6;
}
div.topic {
background-color: #eee;
}
div.warning {
background-color: #ffe4e4;
border: 1px solid #f66;
}
p.admonition-title {
display: inline;
}
p.admonition-title:after {
content: ":";
}
pre {
padding: 5px;
background-color: #eeffcc;
color: #333333;
line-height: 120%;
border: 1px solid #ac9;
border-left: none;
border-right: none;
}
tt {
background-color: #ecf0f3;
padding: 0 1px 0 1px;
font-size: 0.95em;
}
th {
background-color: #ede;
}
.warning tt {
background: #efc2c2;
}
.note tt {
background: #d6d6d6;
}
.viewcode-back {
font-family: sans-serif;
}
div.viewcode-block:target {
background-color: #f4debf;
border-top: 1px solid #ac9;
border-bottom: 1px solid #ac9;
}
@import url("classic.css");

View File

@@ -124,6 +124,7 @@ var Documentation = {
this.fixFirefoxAnchorBug();
this.highlightSearchWords();
this.initIndexTable();
},
/**
@@ -252,6 +253,29 @@ var Documentation = {
});
var url = parts.join('/');
return path.substring(url.lastIndexOf('/') + 1, path.length - 1);
},
initOnKeyListeners: function() {
$(document).keyup(function(event) {
var activeElementType = document.activeElement.tagName;
// don't navigate when in search box or textarea
if (activeElementType !== 'TEXTAREA' && activeElementType !== 'INPUT' && activeElementType !== 'SELECT') {
switch (event.keyCode) {
case 37: // left
var prevHref = $('link[rel="prev"]').prop('href');
if (prevHref) {
window.location.href = prevHref;
return false;
}
case 39: // right
var nextHref = $('link[rel="next"]').prop('href');
if (nextHref) {
window.location.href = nextHref;
return false;
}
}
}
});
}
};
@@ -260,4 +284,4 @@ _ = Documentation.gettext;
$(document).ready(function() {
Documentation.init();
});
});

Binary file not shown.

Before

Width:  |  Height:  |  Size: 347 B

After

Width:  |  Height:  |  Size: 222 B

BIN
doc/_static/down.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 347 B

After

Width:  |  Height:  |  Size: 202 B

BIN
doc/_static/file.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 358 B

After

Width:  |  Height:  |  Size: 286 B

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

BIN
doc/_static/minus.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 173 B

After

Width:  |  Height:  |  Size: 90 B

BIN
doc/_static/plus.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 173 B

After

Width:  |  Height:  |  Size: 90 B

View File

@@ -2,7 +2,7 @@
* searchtools.js_t
* ~~~~~~~~~~~~~~~~
*
* Sphinx JavaScript utilties for the full-text search.
* Sphinx JavaScript utilities for the full-text search.
*
* :copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.
@@ -226,6 +226,106 @@ var Scorer = {
};
var splitChars = (function() {
var result = {};
var singles = [96, 180, 187, 191, 215, 247, 749, 885, 903, 907, 909, 930, 1014, 1648,
1748, 1809, 2416, 2473, 2481, 2526, 2601, 2609, 2612, 2615, 2653, 2702,
2706, 2729, 2737, 2740, 2857, 2865, 2868, 2910, 2928, 2948, 2961, 2971,
2973, 3085, 3089, 3113, 3124, 3213, 3217, 3241, 3252, 3295, 3341, 3345,
3369, 3506, 3516, 3633, 3715, 3721, 3736, 3744, 3748, 3750, 3756, 3761,
3781, 3912, 4239, 4347, 4681, 4695, 4697, 4745, 4785, 4799, 4801, 4823,
4881, 5760, 5901, 5997, 6313, 7405, 8024, 8026, 8028, 8030, 8117, 8125,
8133, 8181, 8468, 8485, 8487, 8489, 8494, 8527, 11311, 11359, 11687, 11695,
11703, 11711, 11719, 11727, 11735, 12448, 12539, 43010, 43014, 43019, 43587,
43696, 43713, 64286, 64297, 64311, 64317, 64319, 64322, 64325, 65141];
var i, j, start, end;
for (i = 0; i < singles.length; i++) {
result[singles[i]] = true;
}
var ranges = [[0, 47], [58, 64], [91, 94], [123, 169], [171, 177], [182, 184], [706, 709],
[722, 735], [741, 747], [751, 879], [888, 889], [894, 901], [1154, 1161],
[1318, 1328], [1367, 1368], [1370, 1376], [1416, 1487], [1515, 1519], [1523, 1568],
[1611, 1631], [1642, 1645], [1750, 1764], [1767, 1773], [1789, 1790], [1792, 1807],
[1840, 1868], [1958, 1968], [1970, 1983], [2027, 2035], [2038, 2041], [2043, 2047],
[2070, 2073], [2075, 2083], [2085, 2087], [2089, 2307], [2362, 2364], [2366, 2383],
[2385, 2391], [2402, 2405], [2419, 2424], [2432, 2436], [2445, 2446], [2449, 2450],
[2483, 2485], [2490, 2492], [2494, 2509], [2511, 2523], [2530, 2533], [2546, 2547],
[2554, 2564], [2571, 2574], [2577, 2578], [2618, 2648], [2655, 2661], [2672, 2673],
[2677, 2692], [2746, 2748], [2750, 2767], [2769, 2783], [2786, 2789], [2800, 2820],
[2829, 2830], [2833, 2834], [2874, 2876], [2878, 2907], [2914, 2917], [2930, 2946],
[2955, 2957], [2966, 2968], [2976, 2978], [2981, 2983], [2987, 2989], [3002, 3023],
[3025, 3045], [3059, 3076], [3130, 3132], [3134, 3159], [3162, 3167], [3170, 3173],
[3184, 3191], [3199, 3204], [3258, 3260], [3262, 3293], [3298, 3301], [3312, 3332],
[3386, 3388], [3390, 3423], [3426, 3429], [3446, 3449], [3456, 3460], [3479, 3481],
[3518, 3519], [3527, 3584], [3636, 3647], [3655, 3663], [3674, 3712], [3717, 3718],
[3723, 3724], [3726, 3731], [3752, 3753], [3764, 3772], [3774, 3775], [3783, 3791],
[3802, 3803], [3806, 3839], [3841, 3871], [3892, 3903], [3949, 3975], [3980, 4095],
[4139, 4158], [4170, 4175], [4182, 4185], [4190, 4192], [4194, 4196], [4199, 4205],
[4209, 4212], [4226, 4237], [4250, 4255], [4294, 4303], [4349, 4351], [4686, 4687],
[4702, 4703], [4750, 4751], [4790, 4791], [4806, 4807], [4886, 4887], [4955, 4968],
[4989, 4991], [5008, 5023], [5109, 5120], [5741, 5742], [5787, 5791], [5867, 5869],
[5873, 5887], [5906, 5919], [5938, 5951], [5970, 5983], [6001, 6015], [6068, 6102],
[6104, 6107], [6109, 6111], [6122, 6127], [6138, 6159], [6170, 6175], [6264, 6271],
[6315, 6319], [6390, 6399], [6429, 6469], [6510, 6511], [6517, 6527], [6572, 6592],
[6600, 6607], [6619, 6655], [6679, 6687], [6741, 6783], [6794, 6799], [6810, 6822],
[6824, 6916], [6964, 6980], [6988, 6991], [7002, 7042], [7073, 7085], [7098, 7167],
[7204, 7231], [7242, 7244], [7294, 7400], [7410, 7423], [7616, 7679], [7958, 7959],
[7966, 7967], [8006, 8007], [8014, 8015], [8062, 8063], [8127, 8129], [8141, 8143],
[8148, 8149], [8156, 8159], [8173, 8177], [8189, 8303], [8306, 8307], [8314, 8318],
[8330, 8335], [8341, 8449], [8451, 8454], [8456, 8457], [8470, 8472], [8478, 8483],
[8506, 8507], [8512, 8516], [8522, 8525], [8586, 9311], [9372, 9449], [9472, 10101],
[10132, 11263], [11493, 11498], [11503, 11516], [11518, 11519], [11558, 11567],
[11622, 11630], [11632, 11647], [11671, 11679], [11743, 11822], [11824, 12292],
[12296, 12320], [12330, 12336], [12342, 12343], [12349, 12352], [12439, 12444],
[12544, 12548], [12590, 12592], [12687, 12689], [12694, 12703], [12728, 12783],
[12800, 12831], [12842, 12880], [12896, 12927], [12938, 12976], [12992, 13311],
[19894, 19967], [40908, 40959], [42125, 42191], [42238, 42239], [42509, 42511],
[42540, 42559], [42592, 42593], [42607, 42622], [42648, 42655], [42736, 42774],
[42784, 42785], [42889, 42890], [42893, 43002], [43043, 43055], [43062, 43071],
[43124, 43137], [43188, 43215], [43226, 43249], [43256, 43258], [43260, 43263],
[43302, 43311], [43335, 43359], [43389, 43395], [43443, 43470], [43482, 43519],
[43561, 43583], [43596, 43599], [43610, 43615], [43639, 43641], [43643, 43647],
[43698, 43700], [43703, 43704], [43710, 43711], [43715, 43738], [43742, 43967],
[44003, 44015], [44026, 44031], [55204, 55215], [55239, 55242], [55292, 55295],
[57344, 63743], [64046, 64047], [64110, 64111], [64218, 64255], [64263, 64274],
[64280, 64284], [64434, 64466], [64830, 64847], [64912, 64913], [64968, 65007],
[65020, 65135], [65277, 65295], [65306, 65312], [65339, 65344], [65371, 65381],
[65471, 65473], [65480, 65481], [65488, 65489], [65496, 65497]];
for (i = 0; i < ranges.length; i++) {
start = ranges[i][0];
end = ranges[i][1];
for (j = start; j <= end; j++) {
result[j] = true;
}
}
return result;
})();
function splitQuery(query) {
var result = [];
var start = -1;
for (var i = 0; i < query.length; i++) {
if (splitChars[query.charCodeAt(i)]) {
if (start !== -1) {
result.push(query.slice(start, i));
start = -1;
}
} else if (start === -1) {
start = i;
}
}
if (start !== -1) {
result.push(query.slice(start));
}
return result;
}
/**
* Search Module
*/
@@ -324,7 +424,7 @@ var Search = {
var searchterms = [];
var excluded = [];
var hlterms = [];
var tmp = query.split(/\s+/);
var tmp = splitQuery(query);
var objectterms = [];
for (i = 0; i < tmp.length; i++) {
if (tmp[i] !== "") {
@@ -338,6 +438,10 @@ var Search = {
}
// stem the word
var word = stemmer.stemWord(tmp[i].toLowerCase());
// prevent stemmer from cutting word smaller than two chars
if(word.length < 3 && tmp[i].length >= 3) {
word = tmp[i];
}
var toAppend;
// select the correct list
if (word[0] == '-') {
@@ -435,7 +539,8 @@ var Search = {
displayNextItem();
});
} else if (DOCUMENTATION_OPTIONS.HAS_SOURCE) {
$.ajax({url: DOCUMENTATION_OPTIONS.URL_ROOT + '_sources/' + item[0] + '.txt',
var suffix = DOCUMENTATION_OPTIONS.SOURCELINK_SUFFIX;
$.ajax({url: DOCUMENTATION_OPTIONS.URL_ROOT + '_sources/' + item[5] + (item[5].slice(-suffix.length) === suffix ? '' : suffix),
dataType: "text",
complete: function(jqxhr, textstatus) {
var data = jqxhr.responseText;
@@ -474,6 +579,7 @@ var Search = {
*/
performObjectSearch : function(object, otherterms) {
var filenames = this._index.filenames;
var docnames = this._index.docnames;
var objects = this._index.objects;
var objnames = this._index.objnames;
var titles = this._index.titles;
@@ -527,7 +633,7 @@ var Search = {
} else {
score += Scorer.objPrioDefault;
}
results.push([filenames[match[0]], fullname, '#'+anchor, descr, score]);
results.push([docnames[match[0]], fullname, '#'+anchor, descr, score, filenames[match[0]]]);
}
}
}
@@ -539,6 +645,7 @@ var Search = {
* search for full-text terms in the index
*/
performTermsSearch : function(searchterms, excluded, terms, titleterms) {
var docnames = this._index.docnames;
var filenames = this._index.filenames;
var titles = this._index.titles;
@@ -613,7 +720,7 @@ var Search = {
// select one (max) score for the file.
// for better ranking, we should calculate ranking by using words statistics like basic tf-idf...
var score = $u.max($u.map(fileMap[file], function(w){return scoreMap[file][w]}));
results.push([filenames[file], titles[file], '', null, score]);
results.push([docnames[file], titles[file], '', null, score, filenames[file]]);
}
}
return results;
@@ -623,7 +730,7 @@ var Search = {
* helper function to return a node containing the
* search summary for a given text. keywords is a list
* of stemmed words, hlwords is the list of normal, unstemmed
* words. the first one is used to find the occurance, the
* words. the first one is used to find the occurrence, the
* latter for highlighting it.
*/
makeSearchSummary : function(text, keywords, hlwords) {

View File

@@ -16,7 +16,7 @@
* Once the browser is closed the cookie is deleted and the position
* reset to the default (expanded).
*
* :copyright: Copyright 2007-2014 by the Sphinx team, see AUTHORS.
* :copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.
*
*/

Binary file not shown.

Before

Width:  |  Height:  |  Size: 345 B

After

Width:  |  Height:  |  Size: 214 B

BIN
doc/_static/up.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 345 B

After

Width:  |  Height:  |  Size: 203 B

View File

@@ -2,7 +2,7 @@
* websupport.js
* ~~~~~~~~~~~~~
*
* sphinx.websupport utilties for all documentation.
* sphinx.websupport utilities for all documentation.
*
* :copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.

View File

@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Authors &mdash; Eventlet 0.20.0 documentation</title>
<title>Authors &#8212; 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" />
@@ -17,13 +17,15 @@
VERSION: '0.20.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
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="top" title="Eventlet 0.20.0 documentation" href="index.html" />
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="History" href="history.html" />
<link rel="prev" title="eventlet.green.zmq ØMQ support" href="modules/zmq.html" />
</head>
@@ -43,7 +45,7 @@
<li class="right" >
<a href="modules/zmq.html" title="eventlet.green.zmq ØMQ support"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
</ul>
</div>
@@ -234,21 +236,18 @@
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/authors.txt"
<li><a href="_sources/authors.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">
<input type="text" name="q" />
<input type="submit" value="Go" />
<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>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
@@ -270,13 +269,13 @@
<li class="right" >
<a href="modules/zmq.html" title="eventlet.green.zmq ØMQ support"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
</ul>
</div>
<div class="footer" role="contentinfo">
&copy; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.5.
&#169; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

View File

@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Basic Usage &mdash; Eventlet 0.20.0 documentation</title>
<title>Basic Usage &#8212; 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" />
@@ -17,13 +17,15 @@
VERSION: '0.20.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
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="top" title="Eventlet 0.20.0 documentation" href="index.html" />
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Design Patterns" href="design_patterns.html" />
<link rel="prev" title="Eventlet Documentation" href="index.html" />
</head>
@@ -43,7 +45,7 @@
<li class="right" >
<a href="index.html" title="Eventlet Documentation"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
</ul>
</div>
@@ -54,7 +56,7 @@
<div class="section" id="basic-usage">
<h1>Basic Usage<a class="headerlink" href="#basic-usage" title="Permalink to this headline"></a></h1>
<p>If it&#8217;s your first time to Eventlet, you may find the illuminated examples in the <a class="reference internal" href="design_patterns.html#design-patterns"><span>Design Patterns</span></a> document to be a good starting point.</p>
<p>If it&#8217;s your first time to Eventlet, you may find the illuminated examples in the <a class="reference internal" href="design_patterns.html#design-patterns"><span class="std std-ref">Design Patterns</span></a> document to be a good starting point.</p>
<p>Eventlet is built around the concept of green threads (i.e. coroutines, we use the terms interchangeably) that are launched to do network-related work. Green threads differ from normal threads in two main ways:</p>
<ul class="simple">
<li>Green threads are so cheap they are nearly free. You do not have to conserve green threads like you would normal threads. In general, there will be at least one green thread per network connection.</li>
@@ -126,13 +128,13 @@ See <a class="reference internal" href="modules/timeout.html#eventlet.timeout.Ti
<dl class="function">
<dt id="eventlet.import_patched">
<code class="descclassname">eventlet.</code><code class="descname">import_patched</code><span class="sig-paren">(</span><em>modulename</em>, <em>*additional_modules</em>, <em>**kw_additional_modules</em><span class="sig-paren">)</span><a class="headerlink" href="#eventlet.import_patched" title="Permalink to this definition"></a></dt>
<dd><p>Imports a module in a way that ensures that the module uses &#8220;green&#8221; versions of the standard library modules, so that everything works nonblockingly. The only required argument is the name of the module to be imported. For more information see <a class="reference internal" href="patching.html#import-green"><span>Import Green</span></a>.</p>
<dd><p>Imports a module in a way that ensures that the module uses &#8220;green&#8221; versions of the standard library modules, so that everything works nonblockingly. The only required argument is the name of the module to be imported. For more information see <a class="reference internal" href="patching.html#import-green"><span class="std std-ref">Import Green</span></a>.</p>
</dd></dl>
<dl class="function">
<dt id="eventlet.monkey_patch">
<code class="descclassname">eventlet.</code><code class="descname">monkey_patch</code><span class="sig-paren">(</span><em>all=True</em>, <em>os=False</em>, <em>select=False</em>, <em>socket=False</em>, <em>thread=False</em>, <em>time=False</em><span class="sig-paren">)</span><a class="headerlink" href="#eventlet.monkey_patch" title="Permalink to this definition"></a></dt>
<dd><p>Globally patches certain system modules to be greenthread-friendly. The keyword arguments afford some control over which modules are patched. If <em>all</em> is True, then all modules are patched regardless of the other arguments. If it&#8217;s False, then the rest of the keyword arguments control patching of specific subsections of the standard library. Most patch the single module of the same name (os, time, select). The exceptions are socket, which also patches the ssl module if present; and thread, which patches thread, threading, and Queue. It&#8217;s safe to call monkey_patch multiple times. For more information see <a class="reference internal" href="patching.html#monkey-patch"><span>Monkeypatching the Standard Library</span></a>.</p>
<dd><p>Globally patches certain system modules to be greenthread-friendly. The keyword arguments afford some control over which modules are patched. If <em>all</em> is True, then all modules are patched regardless of the other arguments. If it&#8217;s False, then the rest of the keyword arguments control patching of specific subsections of the standard library. Most patch the single module of the same name (os, time, select). The exceptions are socket, which also patches the ssl module if present; and thread, which patches thread, threading, and Queue. It&#8217;s safe to call monkey_patch multiple times. For more information see <a class="reference internal" href="patching.html#monkey-patch"><span class="std std-ref">Monkeypatching the Standard Library</span></a>.</p>
</dd></dl>
</div>
@@ -148,7 +150,7 @@ See <a class="reference internal" href="modules/timeout.html#eventlet.timeout.Ti
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>addr</strong> &#8211; Address of the server to connect to. For TCP sockets, this is a (host, port) tuple.</li>
<li><strong>family</strong> &#8211; Socket family, optional. See <a class="reference external" href="http://docs.python.org/library/socket.html#module-socket" title="(in Python v2.7)"><code class="xref py py-mod docutils literal"><span class="pre">socket</span></code></a> documentation for available families.</li>
<li><strong>family</strong> &#8211; Socket family, optional. See <a class="reference external" href="https://docs.python.org/2/library/socket.html#module-socket" title="(in Python v2.7)"><code class="xref py py-mod docutils literal"><span class="pre">socket</span></code></a> documentation for available families.</li>
<li><strong>bind</strong> &#8211; Local address to bind to, optional.</li>
</ul>
</td>
@@ -172,7 +174,7 @@ socket can be used in <a class="reference internal" href="#eventlet.serve" title
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>addr</strong> &#8211; Address to listen on. For TCP sockets, this is a (host, port) tuple.</li>
<li><strong>family</strong> &#8211; Socket family, optional. See <a class="reference external" href="http://docs.python.org/library/socket.html#module-socket" title="(in Python v2.7)"><code class="xref py py-mod docutils literal"><span class="pre">socket</span></code></a> documentation for available families.</li>
<li><strong>family</strong> &#8211; Socket family, optional. See <a class="reference external" href="https://docs.python.org/2/library/socket.html#module-socket" title="(in Python v2.7)"><code class="xref py py-mod docutils literal"><span class="pre">socket</span></code></a> documentation for available families.</li>
<li><strong>backlog</strong> &#8211; The maximum number of queued connections. Should be at least 1; the maximum
value is system-dependent.</li>
</ul>
@@ -189,7 +191,7 @@ value is system-dependent.</li>
<dt id="eventlet.wrap_ssl">
<code class="descclassname">eventlet.</code><code class="descname">wrap_ssl</code><span class="sig-paren">(</span><em>sock</em>, <em>*a</em>, <em>**kw</em><span class="sig-paren">)</span><a class="headerlink" href="#eventlet.wrap_ssl" title="Permalink to this definition"></a></dt>
<dd><p>Convenience function for converting a regular socket into an
SSL socket. Has the same interface as <a class="reference external" href="http://docs.python.org/library/ssl.html#ssl.wrap_socket" title="(in Python v2.7)"><code class="xref py py-func docutils literal"><span class="pre">ssl.wrap_socket()</span></code></a>,
SSL socket. Has the same interface as <a class="reference external" href="https://docs.python.org/2/library/ssl.html#ssl.wrap_socket" title="(in Python v2.7)"><code class="xref py py-func docutils literal"><span class="pre">ssl.wrap_socket()</span></code></a>,
but can also use PyOpenSSL. Though, note that it ignores the
<cite>cert_reqs</cite>, <cite>ssl_version</cite>, <cite>ca_certs</cite>, <cite>do_handshake_on_connect</cite>,
and <cite>suppress_ragged_eofs</cite> arguments when using PyOpenSSL.</p>
@@ -207,8 +209,8 @@ session.</p>
<dd><p>Runs a server on the supplied socket. Calls the function <em>handle</em> in a
separate greenthread for every incoming client connection. <em>handle</em> takes
two arguments: the client socket object, and the client address:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">myhandle</span><span class="p">(</span><span class="n">client_sock</span><span class="p">,</span> <span class="n">client_addr</span><span class="p">):</span>
<span class="k">print</span><span class="p">(</span><span class="s2">&quot;client connected&quot;</span><span class="p">,</span> <span class="n">client_addr</span><span class="p">)</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">myhandle</span><span class="p">(</span><span class="n">client_sock</span><span class="p">,</span> <span class="n">client_addr</span><span class="p">):</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;client connected&quot;</span><span class="p">,</span> <span class="n">client_addr</span><span class="p">)</span>
<span class="n">eventlet</span><span class="o">.</span><span class="n">serve</span><span class="p">(</span><span class="n">eventlet</span><span class="o">.</span><span class="n">listen</span><span class="p">((</span><span class="s1">&#39;127.0.0.1&#39;</span><span class="p">,</span> <span class="mi">9999</span><span class="p">)),</span> <span class="n">myhandle</span><span class="p">)</span>
</pre></div>
@@ -236,7 +238,7 @@ connections until the existing ones complete.</p>
<dd><p>Exception class used for quitting <a class="reference internal" href="#eventlet.serve" title="eventlet.serve"><code class="xref py py-func docutils literal"><span class="pre">serve()</span></code></a> gracefully.</p>
</dd></dl>
<p>These are the basic primitives of Eventlet; there are a lot more out there in the other Eventlet modules; check out the <a class="reference internal" href="modules.html"><em>Module Reference</em></a>.</p>
<p>These are the basic primitives of Eventlet; there are a lot more out there in the other Eventlet modules; check out the <a class="reference internal" href="modules.html"><span class="doc">Module Reference</span></a>.</p>
</div>
</div>
@@ -267,21 +269,18 @@ connections until the existing ones complete.</p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/basic_usage.txt"
<li><a href="_sources/basic_usage.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">
<input type="text" name="q" />
<input type="submit" value="Go" />
<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>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
@@ -303,13 +302,13 @@ connections until the existing ones complete.</p>
<li class="right" >
<a href="index.html" title="Eventlet Documentation"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
</ul>
</div>
<div class="footer" role="contentinfo">
&copy; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.5.
&#169; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

View File

@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>0.20.0 &mdash; Eventlet 0.20.0 documentation</title>
<title>0.20.0 &#8212; 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" />
@@ -17,13 +17,15 @@
VERSION: '0.20.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
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="top" title="Eventlet 0.20.0 documentation" href="index.html" />
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
</head>
<body role="document">
<div class="related" role="navigation" aria-label="related navigation">
@@ -35,7 +37,7 @@
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
</ul>
</div>
@@ -575,23 +577,17 @@ errors</p>
</div>
<div class="section" id="id39">
<h1>0.9.0<a class="headerlink" href="#id39" title="Permalink to this headline"></a></h1>
<ul>
<li><p class="first">Full-duplex sockets (simultaneous readers and writers in the same process).</p>
</li>
<ul class="simple">
<li>Full-duplex sockets (simultaneous readers and writers in the same process).</li>
<li><dl class="first docutils">
<dt>Remove modules that distract from the core mission of making it straightforward to write event-driven networking apps:</dt>
<dd><p class="first last">httpd, httpc, channel, greenlib, httpdate, jsonhttp, logutil</p>
</dd>
<dd>httpd, httpc, channel, greenlib, httpdate, jsonhttp, logutil</dd>
</dl>
</li>
<li><p class="first">Removed test dependency on sqlite, using nose instead.</p>
</li>
<li><p class="first">Marked known-broken tests using nose&#8217;s mechanism (most of these are not broken but are simply run in the incorrect context, such as threading-related tests that are incompatible with the libevent hub).</p>
</li>
<li><p class="first">Remove copied code from python standard libs (in tests).</p>
</li>
<li><p class="first">Added eventlet.patcher which can be used to import &#8220;greened&#8221; modules.</p>
</li>
<li>Removed test dependency on sqlite, using nose instead.</li>
<li>Marked known-broken tests using nose&#8217;s mechanism (most of these are not broken but are simply run in the incorrect context, such as threading-related tests that are incompatible with the libevent hub).</li>
<li>Remove copied code from python standard libs (in tests).</li>
<li>Added eventlet.patcher which can be used to import &#8220;greened&#8221; modules.</li>
</ul>
</div>
<div class="section" id="id40">
@@ -778,21 +774,18 @@ Thanks to Marcus Cavanaugh for pointing out some coros.queue(0) bugs.</p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/changelog.txt"
<li><a href="_sources/changelog.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">
<input type="text" name="q" />
<input type="submit" value="Go" />
<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>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
@@ -808,13 +801,13 @@ Thanks to Marcus Cavanaugh for pointing out some coros.queue(0) bugs.</p>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
</ul>
</div>
<div class="footer" role="contentinfo">
&copy; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.5.
&#169; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

View File

@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Design Patterns &mdash; Eventlet 0.20.0 documentation</title>
<title>Design Patterns &#8212; 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" />
@@ -17,13 +17,15 @@
VERSION: '0.20.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
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="top" title="Eventlet 0.20.0 documentation" href="index.html" />
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Greening The World" href="patching.html" />
<link rel="prev" title="Basic Usage" href="basic_usage.html" />
</head>
@@ -43,7 +45,7 @@
<li class="right" >
<a href="basic_usage.html" title="Basic Usage"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
</ul>
</div>
@@ -58,8 +60,8 @@
<div class="section" id="client-pattern">
<h2>Client Pattern<a class="headerlink" href="#client-pattern" title="Permalink to this headline"></a></h2>
<p>The canonical client-side example is a web crawler. This use case is given a list of urls and wants to retrieve their bodies for later processing. Here is a very simple example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">eventlet</span>
<span class="kn">from</span> <span class="nn">eventlet.green</span> <span class="kn">import</span> <span class="n">urllib2</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">eventlet</span>
<span class="kn">from</span> <span class="nn">eventlet.green</span> <span class="k">import</span> <span class="n">urllib2</span>
<span class="n">urls</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;http://www.google.com/intl/en_ALL/images/logo.gif&quot;</span><span class="p">,</span>
<span class="s2">&quot;https://www.python.org/static/img/python-logo.png&quot;</span><span class="p">,</span>
@@ -70,11 +72,11 @@
<span class="n">pool</span> <span class="o">=</span> <span class="n">eventlet</span><span class="o">.</span><span class="n">GreenPool</span><span class="p">()</span>
<span class="k">for</span> <span class="n">body</span> <span class="ow">in</span> <span class="n">pool</span><span class="o">.</span><span class="n">imap</span><span class="p">(</span><span class="n">fetch</span><span class="p">,</span> <span class="n">urls</span><span class="p">):</span>
<span class="k">print</span><span class="p">(</span><span class="s2">&quot;got body&quot;</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">body</span><span class="p">))</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;got body&quot;</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">body</span><span class="p">))</span>
</pre></div>
</div>
<p>There is a slightly more complex version of this in the <a class="reference internal" href="examples.html#web-crawler-example"><span>web crawler example</span></a>. Here&#8217;s a tour of the interesting lines in this crawler.</p>
<p><code class="docutils literal"><span class="pre">from</span> <span class="pre">eventlet.green</span> <span class="pre">import</span> <span class="pre">urllib2</span></code> is how you import a cooperatively-yielding version of urllib2. It is the same in all respects to the standard version, except that it uses green sockets for its communication. This is an example of the <a class="reference internal" href="patching.html#import-green"><span>Import Green</span></a> pattern.</p>
<p>There is a slightly more complex version of this in the <a class="reference internal" href="examples.html#web-crawler-example"><span class="std std-ref">web crawler example</span></a>. Here&#8217;s a tour of the interesting lines in this crawler.</p>
<p><code class="docutils literal"><span class="pre">from</span> <span class="pre">eventlet.green</span> <span class="pre">import</span> <span class="pre">urllib2</span></code> is how you import a cooperatively-yielding version of urllib2. It is the same in all respects to the standard version, except that it uses green sockets for its communication. This is an example of the <a class="reference internal" href="patching.html#import-green"><span class="std std-ref">Import Green</span></a> pattern.</p>
<p><code class="docutils literal"><span class="pre">pool</span> <span class="pre">=</span> <span class="pre">eventlet.GreenPool()</span></code> constructs a <a class="reference internal" href="modules/greenpool.html#eventlet.greenpool.GreenPool" title="eventlet.greenpool.GreenPool"><code class="xref py py-class docutils literal"><span class="pre">GreenPool</span></code></a> of a thousand green threads. Using a pool is good practice because it provides an upper limit on the amount of work that this crawler will be doing simultaneously, which comes in handy when the input data changes dramatically.</p>
<p><code class="docutils literal"><span class="pre">for</span> <span class="pre">body</span> <span class="pre">in</span> <span class="pre">pool.imap(fetch,</span> <span class="pre">urls):</span></code> iterates over the results of calling the fetch function in parallel. <a class="reference internal" href="modules/greenpool.html#eventlet.greenpool.GreenPool.imap" title="eventlet.greenpool.GreenPool.imap"><code class="xref py py-meth docutils literal"><span class="pre">imap</span></code></a> makes the function calls in parallel, and the results are returned in the order that they were executed.</p>
<p>The key aspect of the client pattern is that it involves collecting the results of each function call; the fact that each fetch is done concurrently is essentially an invisible optimization. Note also that imap is memory-bounded and won&#8217;t consume gigabytes of memory if the list of urls grows to the tens of thousands (yes, we had that problem in production once!).</p>
@@ -82,22 +84,22 @@
<div class="section" id="server-pattern">
<h2>Server Pattern<a class="headerlink" href="#server-pattern" title="Permalink to this headline"></a></h2>
<p>Here&#8217;s a simple server-side example, a simple echo server:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">eventlet</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">eventlet</span>
<span class="k">def</span> <span class="nf">handle</span><span class="p">(</span><span class="n">client</span><span class="p">):</span>
<span class="k">while</span> <span class="bp">True</span><span class="p">:</span>
<span class="k">while</span> <span class="kc">True</span><span class="p">:</span>
<span class="n">c</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">recv</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">c</span><span class="p">:</span> <span class="k">break</span>
<span class="n">client</span><span class="o">.</span><span class="n">sendall</span><span class="p">(</span><span class="n">c</span><span class="p">)</span>
<span class="n">server</span> <span class="o">=</span> <span class="n">eventlet</span><span class="o">.</span><span class="n">listen</span><span class="p">((</span><span class="s1">&#39;0.0.0.0&#39;</span><span class="p">,</span> <span class="mi">6000</span><span class="p">))</span>
<span class="n">pool</span> <span class="o">=</span> <span class="n">eventlet</span><span class="o">.</span><span class="n">GreenPool</span><span class="p">(</span><span class="mi">10000</span><span class="p">)</span>
<span class="k">while</span> <span class="bp">True</span><span class="p">:</span>
<span class="k">while</span> <span class="kc">True</span><span class="p">:</span>
<span class="n">new_sock</span><span class="p">,</span> <span class="n">address</span> <span class="o">=</span> <span class="n">server</span><span class="o">.</span><span class="n">accept</span><span class="p">()</span>
<span class="n">pool</span><span class="o">.</span><span class="n">spawn_n</span><span class="p">(</span><span class="n">handle</span><span class="p">,</span> <span class="n">new_sock</span><span class="p">)</span>
</pre></div>
</div>
<p>The file <a class="reference internal" href="examples.html#echo-server-example"><span>echo server example</span></a> contains a somewhat more robust and complex version of this example.</p>
<p>The file <a class="reference internal" href="examples.html#echo-server-example"><span class="std std-ref">echo server example</span></a> contains a somewhat more robust and complex version of this example.</p>
<p><code class="docutils literal"><span class="pre">server</span> <span class="pre">=</span> <span class="pre">eventlet.listen(('0.0.0.0',</span> <span class="pre">6000))</span></code> uses a convenience function to create a listening socket.</p>
<p><code class="docutils literal"><span class="pre">pool</span> <span class="pre">=</span> <span class="pre">eventlet.GreenPool(10000)</span></code> creates a pool of green threads that could handle ten thousand clients.</p>
<p><code class="docutils literal"><span class="pre">pool.spawn_n(handle,</span> <span class="pre">new_sock)</span></code> launches a green thread to handle the new client. The accept loop doesn&#8217;t care about the return value of the <code class="docutils literal"><span class="pre">handle</span></code> function, so it uses <a class="reference internal" href="modules/greenpool.html#eventlet.greenpool.GreenPool.spawn_n" title="eventlet.greenpool.GreenPool.spawn_n"><code class="xref py py-meth docutils literal"><span class="pre">spawn_n</span></code></a>, instead of <a class="reference internal" href="modules/greenpool.html#eventlet.greenpool.GreenPool.spawn" title="eventlet.greenpool.GreenPool.spawn"><code class="xref py py-meth docutils literal"><span class="pre">spawn</span></code></a>.</p>
@@ -107,7 +109,7 @@
<h2>Dispatch Pattern<a class="headerlink" href="#dispatch-pattern" title="Permalink to this headline"></a></h2>
<p>One common use case that Linden Lab runs into all the time is a &#8220;dispatch&#8221; design pattern. This is a server that is also a client of some other services. Proxies, aggregators, job workers, and so on are all terms that apply here. This is the use case that the <a class="reference internal" href="modules/greenpool.html#eventlet.greenpool.GreenPile" title="eventlet.greenpool.GreenPile"><code class="xref py py-class docutils literal"><span class="pre">GreenPile</span></code></a> was designed for.</p>
<p>Here&#8217;s a somewhat contrived example: a server that receives POSTs from clients that contain a list of urls of RSS feeds. The server fetches all the feeds concurrently and responds with a list of their titles to the client. It&#8217;s easy to imagine it doing something more complex than this, and this could be easily modified to become a Reader-style application:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">eventlet</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">eventlet</span>
<span class="n">feedparser</span> <span class="o">=</span> <span class="n">eventlet</span><span class="o">.</span><span class="n">import_patched</span><span class="p">(</span><span class="s1">&#39;feedparser&#39;</span><span class="p">)</span>
<span class="n">pool</span> <span class="o">=</span> <span class="n">eventlet</span><span class="o">.</span><span class="n">GreenPool</span><span class="p">()</span>
@@ -125,13 +127,13 @@
<span class="k">return</span> <span class="p">[</span><span class="n">titles</span><span class="p">]</span>
</pre></div>
</div>
<p>The full version of this example is in the <a class="reference internal" href="examples.html#feed-scraper-example"><span>Feed Scraper</span></a>, which includes code to start the WSGI server on a particular port.</p>
<p>The full version of this example is in the <a class="reference internal" href="examples.html#feed-scraper-example"><span class="std std-ref">Feed Scraper</span></a>, which includes code to start the WSGI server on a particular port.</p>
<p>This example uses a global (gasp) <a class="reference internal" href="modules/greenpool.html#eventlet.greenpool.GreenPool" title="eventlet.greenpool.GreenPool"><code class="xref py py-class docutils literal"><span class="pre">GreenPool</span></code></a> to control concurrency. If we didn&#8217;t have a global limit on the number of outgoing requests, then a client could cause the server to open tens of thousands of concurrent connections to external servers, thereby getting feedscraper&#8217;s IP banned, or various other accidental-or-on-purpose bad behavior. The pool isn&#8217;t a complete DoS protection, but it&#8217;s the bare minimum.</p>
<p>The interesting lines are in the app function:</p>
<div class="highlight-python"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
2
3
4</pre></div></td><td class="code"><div class="highlight"><pre><span class="n">pile</span> <span class="o">=</span> <span class="n">eventlet</span><span class="o">.</span><span class="n">GreenPile</span><span class="p">(</span><span class="n">pool</span><span class="p">)</span>
4</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="n">pile</span> <span class="o">=</span> <span class="n">eventlet</span><span class="o">.</span><span class="n">GreenPile</span><span class="p">(</span><span class="n">pool</span><span class="p">)</span>
<span class="k">for</span> <span class="n">url</span> <span class="ow">in</span> <span class="n">environ</span><span class="p">[</span><span class="s1">&#39;wsgi.input&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">readlines</span><span class="p">():</span>
<span class="n">pile</span><span class="o">.</span><span class="n">spawn</span><span class="p">(</span><span class="n">fetch_title</span><span class="p">,</span> <span class="n">url</span><span class="p">)</span>
<span class="n">titles</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">pile</span><span class="p">)</span>
@@ -168,21 +170,18 @@
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/design_patterns.txt"
<li><a href="_sources/design_patterns.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">
<input type="text" name="q" />
<input type="submit" value="Go" />
<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>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
@@ -204,13 +203,13 @@
<li class="right" >
<a href="basic_usage.html" title="Basic Usage"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
</ul>
</div>
<div class="footer" role="contentinfo">
&copy; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.5.
&#169; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

View File

@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Environment Variables &mdash; Eventlet 0.20.0 documentation</title>
<title>Environment Variables &#8212; 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" />
@@ -17,13 +17,15 @@
VERSION: '0.20.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
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="top" title="Eventlet 0.20.0 documentation" href="index.html" />
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Module Reference" href="modules.html" />
<link rel="prev" title="Testing Eventlet" href="testing.html" />
</head>
@@ -43,7 +45,7 @@
<li class="right" >
<a href="testing.html" title="Testing Eventlet"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
</ul>
</div>
@@ -59,7 +61,7 @@ These are only for the advanced user.</p>
<p>EVENTLET_HUB</p>
<blockquote>
<div>Used to force Eventlet to use the specified hub instead of the
optimal one. See <a class="reference internal" href="hubs.html#understanding-hubs"><span>Understanding Eventlet Hubs</span></a> for the list of
optimal one. See <a class="reference internal" href="hubs.html#understanding-hubs"><span class="std std-ref">Understanding Eventlet Hubs</span></a> for the list of
acceptable hubs and what they mean (note that picking a hub not on
the list will silently fail). Equivalent to calling
<a class="reference internal" href="hubs.html#eventlet.hubs.use_hub" title="eventlet.hubs.use_hub"><code class="xref py py-meth docutils literal"><span class="pre">eventlet.hubs.use_hub()</span></code></a> at the beginning of the program.</div></blockquote>
@@ -85,21 +87,18 @@ use, so any control of the pool size needs to happen before then.</div></blockqu
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/environment.txt"
<li><a href="_sources/environment.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">
<input type="text" name="q" />
<input type="submit" value="Go" />
<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>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
@@ -121,13 +120,13 @@ use, so any control of the pool size needs to happen before then.</div></blockqu
<li class="right" >
<a href="testing.html" title="Testing Eventlet"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
</ul>
</div>
<div class="footer" role="contentinfo">
&copy; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.5.
&#169; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

View File

@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Examples &mdash; Eventlet 0.20.0 documentation</title>
<title>Examples &#8212; 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" />
@@ -17,13 +17,15 @@
VERSION: '0.20.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
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="top" title="Eventlet 0.20.0 documentation" href="index.html" />
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Using SSL With Eventlet" href="ssl.html" />
<link rel="prev" title="Greening The World" href="patching.html" />
</head>
@@ -43,7 +45,7 @@
<li class="right" >
<a href="patching.html" title="Greening The World"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
</ul>
</div>
@@ -58,7 +60,7 @@
<div class="section" id="web-crawler">
<span id="web-crawler-example"></span><h2>Web Crawler<a class="headerlink" href="#web-crawler" title="Permalink to this headline"></a></h2>
<p><code class="docutils literal"><span class="pre">examples/webcrawler.py</span></code></p>
<div class="highlight-python"><div class="highlight"><pre><span class="ch">#!/usr/bin/env python</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="ch">#!/usr/bin/env python</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">This is a simple web &quot;crawler&quot; that fetches a bunch of urls using a pool to</span>
<span class="sd">control the number of outbound connections. It has as many simultaneously open</span>
@@ -68,7 +70,7 @@
<span class="sd">requests are truly made in parallel.</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="kn">import</span> <span class="nn">eventlet</span>
<span class="kn">from</span> <span class="nn">eventlet.green</span> <span class="kn">import</span> <span class="n">urllib2</span>
<span class="kn">from</span> <span class="nn">eventlet.green</span> <span class="k">import</span> <span class="n">urllib2</span>
<span class="n">urls</span> <span class="o">=</span> <span class="p">[</span>
@@ -79,22 +81,22 @@
<span class="k">def</span> <span class="nf">fetch</span><span class="p">(</span><span class="n">url</span><span class="p">):</span>
<span class="k">print</span><span class="p">(</span><span class="s2">&quot;opening&quot;</span><span class="p">,</span> <span class="n">url</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;opening&quot;</span><span class="p">,</span> <span class="n">url</span><span class="p">)</span>
<span class="n">body</span> <span class="o">=</span> <span class="n">urllib2</span><span class="o">.</span><span class="n">urlopen</span><span class="p">(</span><span class="n">url</span><span class="p">)</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
<span class="k">print</span><span class="p">(</span><span class="s2">&quot;done with&quot;</span><span class="p">,</span> <span class="n">url</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;done with&quot;</span><span class="p">,</span> <span class="n">url</span><span class="p">)</span>
<span class="k">return</span> <span class="n">url</span><span class="p">,</span> <span class="n">body</span>
<span class="n">pool</span> <span class="o">=</span> <span class="n">eventlet</span><span class="o">.</span><span class="n">GreenPool</span><span class="p">(</span><span class="mi">200</span><span class="p">)</span>
<span class="k">for</span> <span class="n">url</span><span class="p">,</span> <span class="n">body</span> <span class="ow">in</span> <span class="n">pool</span><span class="o">.</span><span class="n">imap</span><span class="p">(</span><span class="n">fetch</span><span class="p">,</span> <span class="n">urls</span><span class="p">):</span>
<span class="k">print</span><span class="p">(</span><span class="s2">&quot;got body from&quot;</span><span class="p">,</span> <span class="n">url</span><span class="p">,</span> <span class="s2">&quot;of length&quot;</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">body</span><span class="p">))</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;got body from&quot;</span><span class="p">,</span> <span class="n">url</span><span class="p">,</span> <span class="s2">&quot;of length&quot;</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">body</span><span class="p">))</span>
</pre></div>
</div>
</div>
<div class="section" id="wsgi-server">
<span id="wsgi-server-example"></span><h2>WSGI Server<a class="headerlink" href="#wsgi-server" title="Permalink to this headline"></a></h2>
<p><code class="docutils literal"><span class="pre">examples/wsgi.py</span></code></p>
<div class="highlight-python"><div class="highlight"><pre><span class="sd">&quot;&quot;&quot;This is a simple example of running a wsgi application with eventlet.</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="sd">&quot;&quot;&quot;This is a simple example of running a wsgi application with eventlet.</span>
<span class="sd">For a more fully-featured server which supports multiple processes,</span>
<span class="sd">multiple threads, and graceful code reloading, see:</span>
@@ -102,7 +104,7 @@
<span class="sd">&quot;&quot;&quot;</span>
<span class="kn">import</span> <span class="nn">eventlet</span>
<span class="kn">from</span> <span class="nn">eventlet</span> <span class="kn">import</span> <span class="n">wsgi</span>
<span class="kn">from</span> <span class="nn">eventlet</span> <span class="k">import</span> <span class="n">wsgi</span>
<span class="k">def</span> <span class="nf">hello_world</span><span class="p">(</span><span class="n">env</span><span class="p">,</span> <span class="n">start_response</span><span class="p">):</span>
@@ -119,7 +121,7 @@
<div class="section" id="echo-server">
<span id="echo-server-example"></span><h2>Echo Server<a class="headerlink" href="#echo-server" title="Permalink to this headline"></a></h2>
<p><code class="docutils literal"><span class="pre">examples/echoserver.py</span></code></p>
<div class="highlight-python"><div class="highlight"><pre><span class="ch">#! /usr/bin/env python</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="ch">#! /usr/bin/env python</span>
<span class="sd">&quot;&quot;&quot;\</span>
<span class="sd">Simple server that listens on port 6000 and echos back every input to</span>
<span class="sd">the client. To try out the server, start it up by running this file.</span>
@@ -130,30 +132,30 @@
<span class="sd">You terminate your connection by terminating telnet (typically Ctrl-]</span>
<span class="sd">and then &#39;quit&#39;)</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">print_function</span>
<span class="kn">from</span> <span class="nn">__future__</span> <span class="k">import</span> <span class="n">print_function</span>
<span class="kn">import</span> <span class="nn">eventlet</span>
<span class="k">def</span> <span class="nf">handle</span><span class="p">(</span><span class="n">fd</span><span class="p">):</span>
<span class="k">print</span><span class="p">(</span><span class="s2">&quot;client connected&quot;</span><span class="p">)</span>
<span class="k">while</span> <span class="bp">True</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;client connected&quot;</span><span class="p">)</span>
<span class="k">while</span> <span class="kc">True</span><span class="p">:</span>
<span class="c1"># pass through every non-eof line</span>
<span class="n">x</span> <span class="o">=</span> <span class="n">fd</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">x</span><span class="p">:</span>
<span class="k">break</span>
<span class="n">fd</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="n">fd</span><span class="o">.</span><span class="n">flush</span><span class="p">()</span>
<span class="k">print</span><span class="p">(</span><span class="s2">&quot;echoed&quot;</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">end</span><span class="o">=</span><span class="s1">&#39; &#39;</span><span class="p">)</span>
<span class="k">print</span><span class="p">(</span><span class="s2">&quot;client disconnected&quot;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;echoed&quot;</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">end</span><span class="o">=</span><span class="s1">&#39; &#39;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;client disconnected&quot;</span><span class="p">)</span>
<span class="k">print</span><span class="p">(</span><span class="s2">&quot;server socket listening on port 6000&quot;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;server socket listening on port 6000&quot;</span><span class="p">)</span>
<span class="n">server</span> <span class="o">=</span> <span class="n">eventlet</span><span class="o">.</span><span class="n">listen</span><span class="p">((</span><span class="s1">&#39;0.0.0.0&#39;</span><span class="p">,</span> <span class="mi">6000</span><span class="p">))</span>
<span class="n">pool</span> <span class="o">=</span> <span class="n">eventlet</span><span class="o">.</span><span class="n">GreenPool</span><span class="p">()</span>
<span class="k">while</span> <span class="bp">True</span><span class="p">:</span>
<span class="k">while</span> <span class="kc">True</span><span class="p">:</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">new_sock</span><span class="p">,</span> <span class="n">address</span> <span class="o">=</span> <span class="n">server</span><span class="o">.</span><span class="n">accept</span><span class="p">()</span>
<span class="k">print</span><span class="p">(</span><span class="s2">&quot;accepted&quot;</span><span class="p">,</span> <span class="n">address</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;accepted&quot;</span><span class="p">,</span> <span class="n">address</span><span class="p">)</span>
<span class="n">pool</span><span class="o">.</span><span class="n">spawn_n</span><span class="p">(</span><span class="n">handle</span><span class="p">,</span> <span class="n">new_sock</span><span class="o">.</span><span class="n">makefile</span><span class="p">(</span><span class="s1">&#39;rw&#39;</span><span class="p">))</span>
<span class="k">except</span> <span class="p">(</span><span class="ne">SystemExit</span><span class="p">,</span> <span class="ne">KeyboardInterrupt</span><span class="p">):</span>
<span class="k">break</span>
@@ -163,21 +165,21 @@
<div class="section" id="socket-connect">
<span id="socket-connect-example"></span><h2>Socket Connect<a class="headerlink" href="#socket-connect" title="Permalink to this headline"></a></h2>
<p><code class="docutils literal"><span class="pre">examples/connect.py</span></code></p>
<div class="highlight-python"><div class="highlight"><pre><span class="sd">&quot;&quot;&quot;Spawn multiple workers and collect their results.</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="sd">&quot;&quot;&quot;Spawn multiple workers and collect their results.</span>
<span class="sd">Demonstrates how to use the eventlet.green.socket module.</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">print_function</span>
<span class="kn">from</span> <span class="nn">__future__</span> <span class="k">import</span> <span class="n">print_function</span>
<span class="kn">import</span> <span class="nn">eventlet</span>
<span class="kn">from</span> <span class="nn">eventlet.green</span> <span class="kn">import</span> <span class="n">socket</span>
<span class="kn">from</span> <span class="nn">eventlet.green</span> <span class="k">import</span> <span class="n">socket</span>
<span class="k">def</span> <span class="nf">geturl</span><span class="p">(</span><span class="n">url</span><span class="p">):</span>
<span class="n">c</span> <span class="o">=</span> <span class="n">socket</span><span class="o">.</span><span class="n">socket</span><span class="p">()</span>
<span class="n">ip</span> <span class="o">=</span> <span class="n">socket</span><span class="o">.</span><span class="n">gethostbyname</span><span class="p">(</span><span class="n">url</span><span class="p">)</span>
<span class="n">c</span><span class="o">.</span><span class="n">connect</span><span class="p">((</span><span class="n">ip</span><span class="p">,</span> <span class="mi">80</span><span class="p">))</span>
<span class="k">print</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> connected&#39;</span> <span class="o">%</span> <span class="n">url</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> connected&#39;</span> <span class="o">%</span> <span class="n">url</span><span class="p">)</span>
<span class="n">c</span><span class="o">.</span><span class="n">sendall</span><span class="p">(</span><span class="s1">&#39;GET /</span><span class="se">\r\n\r\n</span><span class="s1">&#39;</span><span class="p">)</span>
<span class="k">return</span> <span class="n">c</span><span class="o">.</span><span class="n">recv</span><span class="p">(</span><span class="mi">1024</span><span class="p">)</span>
@@ -190,7 +192,7 @@
<span class="c1"># note that the pile acts as a collection of return values from the functions</span>
<span class="c1"># if any exceptions are raised by the function they&#39;ll get raised here</span>
<span class="k">for</span> <span class="n">url</span><span class="p">,</span> <span class="n">result</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">urls</span><span class="p">,</span> <span class="n">pile</span><span class="p">):</span>
<span class="k">print</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1">: </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="nb">repr</span><span class="p">(</span><span class="n">result</span><span class="p">)[:</span><span class="mi">50</span><span class="p">]))</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1">: </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="nb">repr</span><span class="p">(</span><span class="n">result</span><span class="p">)[:</span><span class="mi">50</span><span class="p">]))</span>
</pre></div>
</div>
</div>
@@ -199,8 +201,8 @@
<p><code class="docutils literal"><span class="pre">examples/chat_server.py</span></code></p>
<p>This is a little different from the echo server, in that it broadcasts the
messages to all participants, not just the sender.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">eventlet</span>
<span class="kn">from</span> <span class="nn">eventlet.green</span> <span class="kn">import</span> <span class="n">socket</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">eventlet</span>
<span class="kn">from</span> <span class="nn">eventlet.green</span> <span class="k">import</span> <span class="n">socket</span>
<span class="n">PORT</span> <span class="o">=</span> <span class="mi">3001</span>
<span class="n">participants</span> <span class="o">=</span> <span class="nb">set</span><span class="p">()</span>
@@ -209,7 +211,7 @@ messages to all participants, not just the sender.</p>
<span class="k">def</span> <span class="nf">read_chat_forever</span><span class="p">(</span><span class="n">writer</span><span class="p">,</span> <span class="n">reader</span><span class="p">):</span>
<span class="n">line</span> <span class="o">=</span> <span class="n">reader</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span>
<span class="k">while</span> <span class="n">line</span><span class="p">:</span>
<span class="k">print</span><span class="p">(</span><span class="s2">&quot;Chat:&quot;</span><span class="p">,</span> <span class="n">line</span><span class="o">.</span><span class="n">strip</span><span class="p">())</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Chat:&quot;</span><span class="p">,</span> <span class="n">line</span><span class="o">.</span><span class="n">strip</span><span class="p">())</span>
<span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">participants</span><span class="p">:</span>
<span class="k">try</span><span class="p">:</span>
<span class="k">if</span> <span class="n">p</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">writer</span><span class="p">:</span> <span class="c1"># Don&#39;t echo</span>
@@ -222,21 +224,21 @@ messages to all participants, not just the sender.</p>
<span class="k">raise</span>
<span class="n">line</span> <span class="o">=</span> <span class="n">reader</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span>
<span class="n">participants</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">writer</span><span class="p">)</span>
<span class="k">print</span><span class="p">(</span><span class="s2">&quot;Participant left chat.&quot;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Participant left chat.&quot;</span><span class="p">)</span>
<span class="k">try</span><span class="p">:</span>
<span class="k">print</span><span class="p">(</span><span class="s2">&quot;ChatServer starting up on port </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">PORT</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;ChatServer starting up on port </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">PORT</span><span class="p">)</span>
<span class="n">server</span> <span class="o">=</span> <span class="n">eventlet</span><span class="o">.</span><span class="n">listen</span><span class="p">((</span><span class="s1">&#39;0.0.0.0&#39;</span><span class="p">,</span> <span class="n">PORT</span><span class="p">))</span>
<span class="k">while</span> <span class="bp">True</span><span class="p">:</span>
<span class="k">while</span> <span class="kc">True</span><span class="p">:</span>
<span class="n">new_connection</span><span class="p">,</span> <span class="n">address</span> <span class="o">=</span> <span class="n">server</span><span class="o">.</span><span class="n">accept</span><span class="p">()</span>
<span class="k">print</span><span class="p">(</span><span class="s2">&quot;Participant joined chat.&quot;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Participant joined chat.&quot;</span><span class="p">)</span>
<span class="n">new_writer</span> <span class="o">=</span> <span class="n">new_connection</span><span class="o">.</span><span class="n">makefile</span><span class="p">(</span><span class="s1">&#39;w&#39;</span><span class="p">)</span>
<span class="n">participants</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">new_writer</span><span class="p">)</span>
<span class="n">eventlet</span><span class="o">.</span><span class="n">spawn_n</span><span class="p">(</span><span class="n">read_chat_forever</span><span class="p">,</span>
<span class="n">new_writer</span><span class="p">,</span>
<span class="n">new_connection</span><span class="o">.</span><span class="n">makefile</span><span class="p">(</span><span class="s1">&#39;r&#39;</span><span class="p">))</span>
<span class="k">except</span> <span class="p">(</span><span class="ne">KeyboardInterrupt</span><span class="p">,</span> <span class="ne">SystemExit</span><span class="p">):</span>
<span class="k">print</span><span class="p">(</span><span class="s2">&quot;ChatServer exiting.&quot;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;ChatServer exiting.&quot;</span><span class="p">)</span>
</pre></div>
</div>
</div>
@@ -244,7 +246,7 @@ messages to all participants, not just the sender.</p>
<span id="feed-scraper-example"></span><h2>Feed Scraper<a class="headerlink" href="#feed-scraper" title="Permalink to this headline"></a></h2>
<p><code class="docutils literal"><span class="pre">examples/feedscraper.py</span></code></p>
<p>This example requires <a class="reference external" href="http://www.feedparser.org/">Feedparser</a> to be installed or on the PYTHONPATH.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="sd">&quot;&quot;&quot;A simple web server that accepts POSTS containing a list of feed urls,</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="sd">&quot;&quot;&quot;A simple web server that accepts POSTS containing a list of feed urls,</span>
<span class="sd">and returns the titles of those feeds.</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="kn">import</span> <span class="nn">eventlet</span>
@@ -279,7 +281,7 @@ messages to all participants, not just the sender.</p>
<span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s1">&#39;__main__&#39;</span><span class="p">:</span>
<span class="kn">from</span> <span class="nn">eventlet</span> <span class="kn">import</span> <span class="n">wsgi</span>
<span class="kn">from</span> <span class="nn">eventlet</span> <span class="k">import</span> <span class="n">wsgi</span>
<span class="n">wsgi</span><span class="o">.</span><span class="n">server</span><span class="p">(</span><span class="n">eventlet</span><span class="o">.</span><span class="n">listen</span><span class="p">((</span><span class="s1">&#39;localhost&#39;</span><span class="p">,</span> <span class="mi">9010</span><span class="p">)),</span> <span class="n">app</span><span class="p">)</span>
</pre></div>
</div>
@@ -287,7 +289,7 @@ messages to all participants, not just the sender.</p>
<div class="section" id="port-forwarder">
<span id="forwarder-example"></span><h2>Port Forwarder<a class="headerlink" href="#port-forwarder" title="Permalink to this headline"></a></h2>
<p><code class="docutils literal"><span class="pre">examples/forwarder.py</span></code></p>
<div class="highlight-python"><div class="highlight"><pre><span class="sd">&quot;&quot;&quot; This is an incredibly simple port forwarder from port 7000 to 22 on</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="sd">&quot;&quot;&quot; This is an incredibly simple port forwarder from port 7000 to 22 on</span>
<span class="sd">localhost. It calls a callback function when the socket is closed, to</span>
<span class="sd">demonstrate one way that you could start to do interesting things by</span>
<span class="sd">starting from a simple framework like this.</span>
@@ -297,12 +299,12 @@ messages to all participants, not just the sender.</p>
<span class="k">def</span> <span class="nf">closed_callback</span><span class="p">():</span>
<span class="k">print</span><span class="p">(</span><span class="s2">&quot;called back&quot;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;called back&quot;</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="n">dest</span><span class="p">,</span> <span class="n">cb</span><span class="o">=</span><span class="k">lambda</span><span class="p">:</span> <span class="bp">None</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="n">dest</span><span class="p">,</span> <span class="n">cb</span><span class="o">=</span><span class="k">lambda</span><span class="p">:</span> <span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Forwards bytes unidirectionally from source to dest&quot;&quot;&quot;</span>
<span class="k">while</span> <span class="bp">True</span><span class="p">:</span>
<span class="k">while</span> <span class="kc">True</span><span class="p">:</span>
<span class="n">d</span> <span class="o">=</span> <span class="n">source</span><span class="o">.</span><span class="n">recv</span><span class="p">(</span><span class="mi">32384</span><span class="p">)</span>
<span class="k">if</span> <span class="n">d</span> <span class="o">==</span> <span class="s1">&#39;&#39;</span><span class="p">:</span>
<span class="n">cb</span><span class="p">()</span>
@@ -310,7 +312,7 @@ messages to all participants, not just the sender.</p>
<span class="n">dest</span><span class="o">.</span><span class="n">sendall</span><span class="p">(</span><span class="n">d</span><span class="p">)</span>
<span class="n">listener</span> <span class="o">=</span> <span class="n">eventlet</span><span class="o">.</span><span class="n">listen</span><span class="p">((</span><span class="s1">&#39;localhost&#39;</span><span class="p">,</span> <span class="mi">7000</span><span class="p">))</span>
<span class="k">while</span> <span class="bp">True</span><span class="p">:</span>
<span class="k">while</span> <span class="kc">True</span><span class="p">:</span>
<span class="n">client</span><span class="p">,</span> <span class="n">addr</span> <span class="o">=</span> <span class="n">listener</span><span class="o">.</span><span class="n">accept</span><span class="p">()</span>
<span class="n">server</span> <span class="o">=</span> <span class="n">eventlet</span><span class="o">.</span><span class="n">connect</span><span class="p">((</span><span class="s1">&#39;localhost&#39;</span><span class="p">,</span> <span class="mi">22</span><span class="p">))</span>
<span class="c1"># two unidirectional forwarders make a bidirectional one</span>
@@ -323,7 +325,7 @@ messages to all participants, not just the sender.</p>
<span id="recursive-crawler-example"></span><h2>Recursive Web Crawler<a class="headerlink" href="#recursive-web-crawler" title="Permalink to this headline"></a></h2>
<p><code class="docutils literal"><span class="pre">examples/recursive_crawler.py</span></code></p>
<p>This is an example recursive web crawler that fetches linked pages from a seed url.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="sd">&quot;&quot;&quot;This is a recursive web crawler. Don&#39;t go pointing this at random sites;</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="sd">&quot;&quot;&quot;This is a recursive web crawler. Don&#39;t go pointing this at random sites;</span>
<span class="sd">it doesn&#39;t respect robots.txt and it is pretty brutal about how quickly it</span>
<span class="sd">fetches pages.</span>
@@ -334,9 +336,9 @@ messages to all participants, not just the sender.</p>
<span class="sd">acts as sort of a job coordinator (and concurrency controller of</span>
<span class="sd">course).</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">with_statement</span>
<span class="kn">from</span> <span class="nn">__future__</span> <span class="k">import</span> <span class="n">with_statement</span>
<span class="kn">from</span> <span class="nn">eventlet.green</span> <span class="kn">import</span> <span class="n">urllib2</span>
<span class="kn">from</span> <span class="nn">eventlet.green</span> <span class="k">import</span> <span class="n">urllib2</span>
<span class="kn">import</span> <span class="nn">eventlet</span>
<span class="kn">import</span> <span class="nn">re</span>
@@ -347,9 +349,9 @@ messages to all participants, not just the sender.</p>
<span class="k">def</span> <span class="nf">fetch</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">seen</span><span class="p">,</span> <span class="n">pool</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Fetch a url, stick any found urls into the seen set, and</span>
<span class="sd"> dispatch any new ones to the pool.&quot;&quot;&quot;</span>
<span class="k">print</span><span class="p">(</span><span class="s2">&quot;fetching&quot;</span><span class="p">,</span> <span class="n">url</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;fetching&quot;</span><span class="p">,</span> <span class="n">url</span><span class="p">)</span>
<span class="n">data</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
<span class="k">with</span> <span class="n">eventlet</span><span class="o">.</span><span class="n">Timeout</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="bp">False</span><span class="p">):</span>
<span class="k">with</span> <span class="n">eventlet</span><span class="o">.</span><span class="n">Timeout</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="kc">False</span><span class="p">):</span>
<span class="n">data</span> <span class="o">=</span> <span class="n">urllib2</span><span class="o">.</span><span class="n">urlopen</span><span class="p">(</span><span class="n">url</span><span class="p">)</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
<span class="k">for</span> <span class="n">url_match</span> <span class="ow">in</span> <span class="n">url_regex</span><span class="o">.</span><span class="n">finditer</span><span class="p">(</span><span class="n">data</span><span class="p">):</span>
<span class="n">new_url</span> <span class="o">=</span> <span class="n">url_match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
@@ -371,8 +373,8 @@ messages to all participants, not just the sender.</p>
<span class="k">return</span> <span class="n">seen</span>
<span class="n">seen</span> <span class="o">=</span> <span class="n">crawl</span><span class="p">(</span><span class="s2">&quot;http://eventlet.net&quot;</span><span class="p">)</span>
<span class="k">print</span><span class="p">(</span><span class="s2">&quot;I saw these urls:&quot;</span><span class="p">)</span>
<span class="k">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">seen</span><span class="p">))</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;I saw these urls:&quot;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">seen</span><span class="p">))</span>
</pre></div>
</div>
</div>
@@ -380,7 +382,7 @@ messages to all participants, not just the sender.</p>
<span id="producer-consumer-example"></span><h2>Producer Consumer Web Crawler<a class="headerlink" href="#producer-consumer-web-crawler" title="Permalink to this headline"></a></h2>
<p><code class="docutils literal"><span class="pre">examples/producer_consumer.py</span></code></p>
<p>This is an example implementation of the producer/consumer pattern as well as being identical in functionality to the recursive web crawler.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="sd">&quot;&quot;&quot;This is a recursive web crawler. Don&#39;t go pointing this at random sites;</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="sd">&quot;&quot;&quot;This is a recursive web crawler. Don&#39;t go pointing this at random sites;</span>
<span class="sd">it doesn&#39;t respect robots.txt and it is pretty brutal about how quickly it</span>
<span class="sd">fetches pages.</span>
@@ -391,9 +393,9 @@ messages to all participants, not just the sender.</p>
<span class="sd">number of &quot;workers&quot;, so you don&#39;t have to write that tedious management code</span>
<span class="sd">yourself.</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">with_statement</span>
<span class="kn">from</span> <span class="nn">__future__</span> <span class="k">import</span> <span class="n">with_statement</span>
<span class="kn">from</span> <span class="nn">eventlet.green</span> <span class="kn">import</span> <span class="n">urllib2</span>
<span class="kn">from</span> <span class="nn">eventlet.green</span> <span class="k">import</span> <span class="n">urllib2</span>
<span class="kn">import</span> <span class="nn">eventlet</span>
<span class="kn">import</span> <span class="nn">re</span>
@@ -403,9 +405,9 @@ messages to all participants, not just the sender.</p>
<span class="k">def</span> <span class="nf">fetch</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">outq</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Fetch a url and push any urls found into a queue.&quot;&quot;&quot;</span>
<span class="k">print</span><span class="p">(</span><span class="s2">&quot;fetching&quot;</span><span class="p">,</span> <span class="n">url</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;fetching&quot;</span><span class="p">,</span> <span class="n">url</span><span class="p">)</span>
<span class="n">data</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
<span class="k">with</span> <span class="n">eventlet</span><span class="o">.</span><span class="n">Timeout</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="bp">False</span><span class="p">):</span>
<span class="k">with</span> <span class="n">eventlet</span><span class="o">.</span><span class="n">Timeout</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="kc">False</span><span class="p">):</span>
<span class="n">data</span> <span class="o">=</span> <span class="n">urllib2</span><span class="o">.</span><span class="n">urlopen</span><span class="p">(</span><span class="n">url</span><span class="p">)</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
<span class="k">for</span> <span class="n">url_match</span> <span class="ow">in</span> <span class="n">url_regex</span><span class="o">.</span><span class="n">finditer</span><span class="p">(</span><span class="n">data</span><span class="p">):</span>
<span class="n">new_url</span> <span class="o">=</span> <span class="n">url_match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
@@ -420,7 +422,7 @@ messages to all participants, not just the sender.</p>
<span class="n">q</span> <span class="o">=</span> <span class="n">eventlet</span><span class="o">.</span><span class="n">Queue</span><span class="p">()</span>
<span class="n">q</span><span class="o">.</span><span class="n">put</span><span class="p">(</span><span class="n">start_url</span><span class="p">)</span>
<span class="c1"># keep looping if there are new urls, or workers that may produce more urls</span>
<span class="k">while</span> <span class="bp">True</span><span class="p">:</span>
<span class="k">while</span> <span class="kc">True</span><span class="p">:</span>
<span class="k">while</span> <span class="ow">not</span> <span class="n">q</span><span class="o">.</span><span class="n">empty</span><span class="p">():</span>
<span class="n">url</span> <span class="o">=</span> <span class="n">q</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
<span class="c1"># limit requests to eventlet.net so we don&#39;t crash all over the internet</span>
@@ -435,8 +437,8 @@ messages to all participants, not just the sender.</p>
<span class="n">seen</span> <span class="o">=</span> <span class="n">producer</span><span class="p">(</span><span class="s2">&quot;http://eventlet.net&quot;</span><span class="p">)</span>
<span class="k">print</span><span class="p">(</span><span class="s2">&quot;I saw these urls:&quot;</span><span class="p">)</span>
<span class="k">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">seen</span><span class="p">))</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;I saw these urls:&quot;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">seen</span><span class="p">))</span>
</pre></div>
</div>
</div>
@@ -445,24 +447,24 @@ messages to all participants, not just the sender.</p>
<p><code class="docutils literal"><span class="pre">examples/websocket.py</span></code></p>
<p>This exercises some of the features of the websocket server
implementation.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">eventlet</span>
<span class="kn">from</span> <span class="nn">eventlet</span> <span class="kn">import</span> <span class="n">wsgi</span>
<span class="kn">from</span> <span class="nn">eventlet</span> <span class="kn">import</span> <span class="n">websocket</span>
<span class="kn">from</span> <span class="nn">eventlet.support</span> <span class="kn">import</span> <span class="n">six</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">eventlet</span>
<span class="kn">from</span> <span class="nn">eventlet</span> <span class="k">import</span> <span class="n">wsgi</span>
<span class="kn">from</span> <span class="nn">eventlet</span> <span class="k">import</span> <span class="n">websocket</span>
<span class="kn">from</span> <span class="nn">eventlet.support</span> <span class="k">import</span> <span class="n">six</span>
<span class="c1"># demo app</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">random</span>
<span class="nd">@websocket.WebSocketWSGI</span>
<span class="nd">@websocket</span><span class="o">.</span><span class="n">WebSocketWSGI</span>
<span class="k">def</span> <span class="nf">handle</span><span class="p">(</span><span class="n">ws</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot; This is the websocket handler function. Note that we</span>
<span class="sd"> can dispatch based on path in here, too.&quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">ws</span><span class="o">.</span><span class="n">path</span> <span class="o">==</span> <span class="s1">&#39;/echo&#39;</span><span class="p">:</span>
<span class="k">while</span> <span class="bp">True</span><span class="p">:</span>
<span class="k">while</span> <span class="kc">True</span><span class="p">:</span>
<span class="n">m</span> <span class="o">=</span> <span class="n">ws</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>
<span class="k">if</span> <span class="n">m</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
<span class="k">if</span> <span class="n">m</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="k">break</span>
<span class="n">ws</span><span class="o">.</span><span class="n">send</span><span class="p">(</span><span class="n">m</span><span class="p">)</span>
@@ -486,7 +488,7 @@ implementation.</p>
<span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s2">&quot;__main__&quot;</span><span class="p">:</span>
<span class="c1"># run an example app from the command line</span>
<span class="n">listener</span> <span class="o">=</span> <span class="n">eventlet</span><span class="o">.</span><span class="n">listen</span><span class="p">((</span><span class="s1">&#39;127.0.0.1&#39;</span><span class="p">,</span> <span class="mi">7000</span><span class="p">))</span>
<span class="k">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">Visit http://localhost:7000/ in your websocket-capable browser.</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">Visit http://localhost:7000/ in your websocket-capable browser.</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="n">wsgi</span><span class="o">.</span><span class="n">server</span><span class="p">(</span><span class="n">listener</span><span class="p">,</span> <span class="n">dispatch</span><span class="p">)</span>
</pre></div>
</div>
@@ -495,24 +497,24 @@ implementation.</p>
<span id="websocket-chat-example"></span><h2>Websocket Multi-User Chat Example<a class="headerlink" href="#websocket-multi-user-chat-example" title="Permalink to this headline"></a></h2>
<p><code class="docutils literal"><span class="pre">examples/websocket_chat.py</span></code></p>
<p>This is a mashup of the websocket example and the multi-user chat example, showing how you can do the same sorts of things with websockets that you can do with regular sockets.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">os</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">eventlet</span>
<span class="kn">from</span> <span class="nn">eventlet</span> <span class="kn">import</span> <span class="n">wsgi</span>
<span class="kn">from</span> <span class="nn">eventlet</span> <span class="kn">import</span> <span class="n">websocket</span>
<span class="kn">from</span> <span class="nn">eventlet</span> <span class="k">import</span> <span class="n">wsgi</span>
<span class="kn">from</span> <span class="nn">eventlet</span> <span class="k">import</span> <span class="n">websocket</span>
<span class="n">PORT</span> <span class="o">=</span> <span class="mi">7000</span>
<span class="n">participants</span> <span class="o">=</span> <span class="nb">set</span><span class="p">()</span>
<span class="nd">@websocket.WebSocketWSGI</span>
<span class="nd">@websocket</span><span class="o">.</span><span class="n">WebSocketWSGI</span>
<span class="k">def</span> <span class="nf">handle</span><span class="p">(</span><span class="n">ws</span><span class="p">):</span>
<span class="n">participants</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">ws</span><span class="p">)</span>
<span class="k">try</span><span class="p">:</span>
<span class="k">while</span> <span class="bp">True</span><span class="p">:</span>
<span class="k">while</span> <span class="kc">True</span><span class="p">:</span>
<span class="n">m</span> <span class="o">=</span> <span class="n">ws</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>
<span class="k">if</span> <span class="n">m</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
<span class="k">if</span> <span class="n">m</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="k">break</span>
<span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">participants</span><span class="p">:</span>
<span class="n">p</span><span class="o">.</span><span class="n">send</span><span class="p">(</span><span class="n">m</span><span class="p">)</span>
@@ -532,7 +534,7 @@ implementation.</p>
<span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s2">&quot;__main__&quot;</span><span class="p">:</span>
<span class="c1"># run an example app from the command line</span>
<span class="n">listener</span> <span class="o">=</span> <span class="n">eventlet</span><span class="o">.</span><span class="n">listen</span><span class="p">((</span><span class="s1">&#39;127.0.0.1&#39;</span><span class="p">,</span> <span class="n">PORT</span><span class="p">))</span>
<span class="k">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">Visit http://localhost:7000/ in your websocket-capable browser.</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">Visit http://localhost:7000/ in your websocket-capable browser.</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="n">wsgi</span><span class="o">.</span><span class="n">server</span><span class="p">(</span><span class="n">listener</span><span class="p">,</span> <span class="n">dispatch</span><span class="p">)</span>
</pre></div>
</div>
@@ -572,21 +574,18 @@ implementation.</p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/examples.txt"
<li><a href="_sources/examples.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">
<input type="text" name="q" />
<input type="submit" value="Go" />
<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>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
@@ -608,13 +607,13 @@ implementation.</p>
<li class="right" >
<a href="patching.html" title="Greening The World"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
</ul>
</div>
<div class="footer" role="contentinfo">
&copy; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.5.
&#169; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

File diff suppressed because it is too large Load Diff

View File

@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>History &mdash; Eventlet 0.20.0 documentation</title>
<title>History &#8212; 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" />
@@ -17,13 +17,15 @@
VERSION: '0.20.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
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="top" title="Eventlet 0.20.0 documentation" href="index.html" />
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="prev" title="Authors" href="authors.html" />
</head>
<body role="document">
@@ -39,7 +41,7 @@
<li class="right" >
<a href="authors.html" title="Authors"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
</ul>
</div>
@@ -70,21 +72,18 @@
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/history.txt"
<li><a href="_sources/history.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">
<input type="text" name="q" />
<input type="submit" value="Go" />
<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>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
@@ -103,13 +102,13 @@
<li class="right" >
<a href="authors.html" title="Authors"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
</ul>
</div>
<div class="footer" role="contentinfo">
&copy; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.5.
&#169; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

View File

@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Understanding Eventlet Hubs &mdash; Eventlet 0.20.0 documentation</title>
<title>Understanding Eventlet Hubs &#8212; 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" />
@@ -17,13 +17,15 @@
VERSION: '0.20.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
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="top" title="Eventlet 0.20.0 documentation" href="index.html" />
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Testing Eventlet" href="testing.html" />
<link rel="prev" title="Zeromq" href="zeromq.html" />
</head>
@@ -43,7 +45,7 @@
<li class="right" >
<a href="zeromq.html" title="Zeromq"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
</ul>
</div>
@@ -66,20 +68,20 @@
<dt><strong>pyevent</strong></dt>
<dd>This is a libevent-based backend and is thus the fastest. It&#8217;s disabled by default, because it does not support native threads, but you can enable it yourself if your use case doesn&#8217;t require them. (You have to install pyevent, too.)</dd>
</dl>
<p>If the selected hub is not ideal for the application, another can be selected. You can make the selection either with the environment variable <a class="reference internal" href="environment.html#env-vars"><span>EVENTLET_HUB</span></a>, or with use_hub.</p>
<p>If the selected hub is not ideal for the application, another can be selected. You can make the selection either with the environment variable <a class="reference internal" href="environment.html#env-vars"><span class="std std-ref">EVENTLET_HUB</span></a>, or with use_hub.</p>
<dl class="function">
<dt id="eventlet.hubs.use_hub">
<code class="descclassname">eventlet.hubs.</code><code class="descname">use_hub</code><span class="sig-paren">(</span><em>hub=None</em><span class="sig-paren">)</span><a class="headerlink" href="#eventlet.hubs.use_hub" title="Permalink to this definition"></a></dt>
<dd><p>Use this to control which hub Eventlet selects. Call it with the name of the desired hub module. Make sure to do this before the application starts doing any I/O! Calling use_hub completely eliminates the old hub, and any file descriptors or timers that it had been managing will be forgotten. Put the call as one of the first lines in the main module.:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="sd">&quot;&quot;&quot; This is the main module &quot;&quot;&quot;</span>
<span class="kn">from</span> <span class="nn">eventlet</span> <span class="kn">import</span> <span class="n">hubs</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="sd">&quot;&quot;&quot; This is the main module &quot;&quot;&quot;</span>
<span class="kn">from</span> <span class="nn">eventlet</span> <span class="k">import</span> <span class="n">hubs</span>
<span class="n">hubs</span><span class="o">.</span><span class="n">use_hub</span><span class="p">(</span><span class="s2">&quot;pyevent&quot;</span><span class="p">)</span>
</pre></div>
</div>
<p>Hubs are implemented as thread-local class instances. <a class="reference internal" href="#eventlet.hubs.use_hub" title="eventlet.hubs.use_hub"><code class="xref py py-func docutils literal"><span class="pre">eventlet.hubs.use_hub()</span></code></a> only operates on the current thread. When using multiple threads that each need their own hub, call <a class="reference internal" href="#eventlet.hubs.use_hub" title="eventlet.hubs.use_hub"><code class="xref py py-func docutils literal"><span class="pre">eventlet.hubs.use_hub()</span></code></a> at the beginning of each thread function that needs a specific hub. In practice, it may not be necessary to specify a hub in each thread; it works to use one special hub for the main thread, and let other threads use the default hub; this hybrid hub configuration will work fine.</p>
<p>It is also possible to use a third-party hub module in place of one of the built-in ones. Simply pass the module itself to <a class="reference internal" href="#eventlet.hubs.use_hub" title="eventlet.hubs.use_hub"><code class="xref py py-func docutils literal"><span class="pre">eventlet.hubs.use_hub()</span></code></a>. The task of writing such a hub is a little beyond the scope of this document, it&#8217;s probably a good idea to simply inspect the code of the existing hubs to see how they work.:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">eventlet</span> <span class="kn">import</span> <span class="n">hubs</span>
<span class="kn">from</span> <span class="nn">mypackage</span> <span class="kn">import</span> <span class="n">myhub</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">eventlet</span> <span class="k">import</span> <span class="n">hubs</span>
<span class="kn">from</span> <span class="nn">mypackage</span> <span class="k">import</span> <span class="n">myhub</span>
<span class="n">hubs</span><span class="o">.</span><span class="n">use_hub</span><span class="p">(</span><span class="n">myhub</span><span class="p">)</span>
</pre></div>
</div>
@@ -171,21 +173,18 @@ unexpectedly without being deprecated first.</p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/hubs.txt"
<li><a href="_sources/hubs.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">
<input type="text" name="q" />
<input type="submit" value="Go" />
<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>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
@@ -207,13 +206,13 @@ unexpectedly without being deprecated first.</p>
<li class="right" >
<a href="zeromq.html" title="Zeromq"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
</ul>
</div>
<div class="footer" role="contentinfo">
&copy; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.5.
&#169; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

View File

@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Eventlet Documentation &mdash; Eventlet 0.20.0 documentation</title>
<title>Eventlet Documentation &#8212; 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" />
@@ -17,13 +17,15 @@
VERSION: '0.20.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
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="top" title="Eventlet 0.20.0 documentation" href="#" />
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Basic Usage" href="basic_usage.html" />
</head>
<body role="document">
@@ -39,7 +41,7 @@
<li class="right" >
<a href="basic_usage.html" title="Basic Usage"
accesskey="N">next</a> |</li>
<li class="nav-item nav-item-0"><a href="#">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="#">Eventlet 0.20.0 documentation</a> &#187;</li>
</ul>
</div>
@@ -51,7 +53,7 @@
<div class="section" id="eventlet-documentation">
<h1>Eventlet Documentation<a class="headerlink" href="#eventlet-documentation" title="Permalink to this headline"></a></h1>
<p>Code talks! This is a simple web crawler that fetches a bunch of urls concurrently:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">urls</span> <span class="o">=</span> <span class="p">[</span>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">urls</span> <span class="o">=</span> <span class="p">[</span>
<span class="s2">&quot;http://www.google.com/intl/en_ALL/images/logo.gif&quot;</span><span class="p">,</span>
<span class="s2">&quot;http://python.org/images/python-logo.gif&quot;</span><span class="p">,</span>
<span class="s2">&quot;http://us.i1.yimg.com/us.yimg.com/i/ww/beta/y3.gif&quot;</span><span class="p">,</span>
@@ -174,9 +176,9 @@
<div class="section" id="indices-and-tables">
<h1>Indices and tables<a class="headerlink" href="#indices-and-tables" title="Permalink to this headline"></a></h1>
<ul class="simple">
<li><a class="reference internal" href="genindex.html"><span>Index</span></a></li>
<li><a class="reference internal" href="py-modindex.html"><span>Module Index</span></a></li>
<li><a class="reference internal" href="search.html"><span>Search Page</span></a></li>
<li><a class="reference internal" href="genindex.html"><span class="std std-ref">Index</span></a></li>
<li><a class="reference internal" href="py-modindex.html"><span class="std std-ref">Module Index</span></a></li>
<li><a class="reference internal" href="search.html"><span class="std std-ref">Search Page</span></a></li>
</ul>
</div>
@@ -202,21 +204,18 @@
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/index.txt"
<li><a href="_sources/index.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">
<input type="text" name="q" />
<input type="submit" value="Go" />
<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>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
@@ -235,13 +234,13 @@
<li class="right" >
<a href="basic_usage.html" title="Basic Usage"
>next</a> |</li>
<li class="nav-item nav-item-0"><a href="#">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="#">Eventlet 0.20.0 documentation</a> &#187;</li>
</ul>
</div>
<div class="footer" role="contentinfo">
&copy; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.5.
&#169; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

View File

@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Module Reference &mdash; Eventlet 0.20.0 documentation</title>
<title>Module Reference &#8212; 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" />
@@ -17,13 +17,15 @@
VERSION: '0.20.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
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="top" title="Eventlet 0.20.0 documentation" href="index.html" />
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="backdoor Python interactive interpreter within a running process" href="modules/backdoor.html" />
<link rel="prev" title="Environment Variables" href="environment.html" />
</head>
@@ -43,7 +45,7 @@
<li class="right" >
<a href="environment.html" title="Environment Variables"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
</ul>
</div>
@@ -105,21 +107,18 @@
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/modules.txt"
<li><a href="_sources/modules.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">
<input type="text" name="q" />
<input type="submit" value="Go" />
<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>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
@@ -141,13 +140,13 @@
<li class="right" >
<a href="environment.html" title="Environment Variables"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
</ul>
</div>
<div class="footer" role="contentinfo">
&copy; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.5.
&#169; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

View File

@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>backdoor Python interactive interpreter within a running process &mdash; Eventlet 0.20.0 documentation</title>
<title>backdoor Python interactive interpreter within a running process &#8212; 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" />
@@ -17,14 +17,15 @@
VERSION: '0.20.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
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="top" title="Eventlet 0.20.0 documentation" href="../index.html" />
<link rel="up" title="Module Reference" href="../modules.html" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="next" title="corolocal Coroutine local storage" href="corolocal.html" />
<link rel="prev" title="Module Reference" href="../modules.html" />
</head>
@@ -44,8 +45,8 @@
<li class="right" >
<a href="../modules.html" title="Module Reference"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" accesskey="U">Module Reference</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" accesskey="U">Module Reference</a> &#187;</li>
</ul>
</div>
@@ -58,11 +59,11 @@
<h1><code class="xref py py-mod docutils literal"><span class="pre">backdoor</span></code> &#8211; Python interactive interpreter within a running process<a class="headerlink" href="#backdoor-python-interactive-interpreter-within-a-running-process" title="Permalink to this headline"></a></h1>
<p>The backdoor module is convenient for inspecting the state of a long-running process. It supplies the normal Python interactive interpreter in a way that does not block the normal operation of the application. This can be useful for debugging, performance tuning, or simply learning about how things behave in situ.</p>
<p>In the application, spawn a greenthread running backdoor_server on a listening socket:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">eventlet</span><span class="o">.</span><span class="n">spawn</span><span class="p">(</span><span class="n">backdoor</span><span class="o">.</span><span class="n">backdoor_server</span><span class="p">,</span> <span class="n">eventlet</span><span class="o">.</span><span class="n">listen</span><span class="p">((</span><span class="s1">&#39;localhost&#39;</span><span class="p">,</span> <span class="mi">3000</span><span class="p">)))</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">eventlet</span><span class="o">.</span><span class="n">spawn</span><span class="p">(</span><span class="n">backdoor</span><span class="o">.</span><span class="n">backdoor_server</span><span class="p">,</span> <span class="n">eventlet</span><span class="o">.</span><span class="n">listen</span><span class="p">((</span><span class="s1">&#39;localhost&#39;</span><span class="p">,</span> <span class="mi">3000</span><span class="p">)))</span>
</pre></div>
</div>
<p>When this is running, the backdoor is accessible via telnet to the specified port.</p>
<div class="highlight-sh"><div class="highlight"><pre>$ telnet localhost 3000
<div class="highlight-sh"><div class="highlight"><pre><span></span>$ telnet localhost 3000
Python 2.6.2 <span class="o">(</span>r262:71600, Apr <span class="m">16</span> 2009, 09:17:39<span class="o">)</span>
<span class="o">[</span>GCC 4.0.1 <span class="o">(</span>Apple Computer, Inc. build 5250<span class="o">)]</span> on darwin
Type <span class="s2">&quot;help&quot;</span>, <span class="s2">&quot;copyright&quot;</span>, <span class="s2">&quot;credits&quot;</span> or <span class="s2">&quot;license&quot;</span> <span class="k">for</span> more information.
@@ -110,21 +111,18 @@ variables in here.</p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/modules/backdoor.txt"
<li><a href="../_sources/modules/backdoor.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">
<input type="text" name="q" />
<input type="submit" value="Go" />
<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>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
@@ -146,14 +144,14 @@ variables in here.</p>
<li class="right" >
<a href="../modules.html" title="Module Reference"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" >Module Reference</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" >Module Reference</a> &#187;</li>
</ul>
</div>
<div class="footer" role="contentinfo">
&copy; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.5.
&#169; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

View File

@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>corolocal Coroutine local storage &mdash; Eventlet 0.20.0 documentation</title>
<title>corolocal Coroutine local storage &#8212; 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" />
@@ -17,14 +17,15 @@
VERSION: '0.20.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
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="top" title="Eventlet 0.20.0 documentation" href="../index.html" />
<link rel="up" title="Module Reference" href="../modules.html" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="next" title="dagpool Dependency-Driven Greenthreads" href="dagpool.html" />
<link rel="prev" title="backdoor Python interactive interpreter within a running process" href="backdoor.html" />
</head>
@@ -44,8 +45,8 @@
<li class="right" >
<a href="backdoor.html" title="backdoor Python interactive interpreter within a running process"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" accesskey="U">Module Reference</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" accesskey="U">Module Reference</a> &#187;</li>
</ul>
</div>
@@ -84,21 +85,18 @@
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/modules/corolocal.txt"
<li><a href="../_sources/modules/corolocal.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">
<input type="text" name="q" />
<input type="submit" value="Go" />
<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>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
@@ -120,14 +118,14 @@
<li class="right" >
<a href="backdoor.html" title="backdoor Python interactive interpreter within a running process"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" >Module Reference</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" >Module Reference</a> &#187;</li>
</ul>
</div>
<div class="footer" role="contentinfo">
&copy; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.5.
&#169; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

View File

@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>dagpool Dependency-Driven Greenthreads &mdash; Eventlet 0.20.0 documentation</title>
<title>dagpool Dependency-Driven Greenthreads &#8212; 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" />
@@ -17,14 +17,15 @@
VERSION: '0.20.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
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="top" title="Eventlet 0.20.0 documentation" href="../index.html" />
<link rel="up" title="Module Reference" href="../modules.html" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="next" title="debug Debugging tools for Eventlet" href="debug.html" />
<link rel="prev" title="corolocal Coroutine local storage" href="corolocal.html" />
</head>
@@ -44,8 +45,8 @@
<li class="right" >
<a href="corolocal.html" title="corolocal Coroutine local storage"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" accesskey="U">Module Reference</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" accesskey="U">Module Reference</a> &#187;</li>
</ul>
</div>
@@ -112,15 +113,15 @@ blocks until the next result can be delivered.</p>
<p>Consider a couple of programs in some compiled language that depend on a set
of precompiled libraries. Suppose every such build requires as input the
specific set of library builds on which it directly depends.</p>
<div class="highlight-python"><div class="highlight"><pre>a zlib
| / |
|/ |
b c
| /|
| / |
| / |
|/ |
d e
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">a</span> <span class="n">zlib</span>
<span class="o">|</span> <span class="o">/</span> <span class="o">|</span>
<span class="o">|/</span> <span class="o">|</span>
<span class="n">b</span> <span class="n">c</span>
<span class="o">|</span> <span class="o">/|</span>
<span class="o">|</span> <span class="o">/</span> <span class="o">|</span>
<span class="o">|</span> <span class="o">/</span> <span class="o">|</span>
<span class="o">|/</span> <span class="o">|</span>
<span class="n">d</span> <span class="n">e</span>
</pre></div>
</div>
<p>We can&#8217;t run the build for program d until we have the build results for both
@@ -128,16 +129,16 @@ b and c. We can&#8217;t run the build for library b until we have build results
a and zlib. We can, however, immediately run the builds for a and zlib.</p>
<p>So we can use a DAGPool instance to spawn greenthreads running a function such
as this:</p>
<div class="highlight-python"><div class="highlight"><pre>def builder(key, upstream):
for libname, product in upstream:
# ... configure build for &#39;key&#39; to use &#39;product&#39; for &#39;libname&#39;
# all upstream builds have completed
# ... run build for &#39;key&#39;
return build_product_for_key
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">builder</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">upstream</span><span class="p">):</span>
<span class="k">for</span> <span class="n">libname</span><span class="p">,</span> <span class="n">product</span> <span class="ow">in</span> <span class="n">upstream</span><span class="p">:</span>
<span class="c1"># ... configure build for &#39;key&#39; to use &#39;product&#39; for &#39;libname&#39;</span>
<span class="c1"># all upstream builds have completed</span>
<span class="c1"># ... run build for &#39;key&#39;</span>
<span class="k">return</span> <span class="n">build_product_for_key</span>
</pre></div>
</div>
<p><a class="reference internal" href="#eventlet.dagpool.DAGPool.spawn" title="eventlet.dagpool.DAGPool.spawn"><code class="xref py py-meth docutils literal"><span class="pre">spawn</span></code></a> all these greenthreads:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">pool</span> <span class="o">=</span> <span class="n">DAGPool</span><span class="p">()</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">pool</span> <span class="o">=</span> <span class="n">DAGPool</span><span class="p">()</span>
<span class="c1"># the upstream producer keys passed to spawn() can be from any iterable,</span>
<span class="c1"># including a generator</span>
<span class="n">pool</span><span class="o">.</span><span class="n">spawn</span><span class="p">(</span><span class="s2">&quot;d&quot;</span><span class="p">,</span> <span class="p">(</span><span class="s2">&quot;b&quot;</span><span class="p">,</span> <span class="s2">&quot;c&quot;</span><span class="p">),</span> <span class="n">builder</span><span class="p">)</span>
@@ -150,7 +151,7 @@ as this:</p>
<p>As with <a class="reference internal" href="../basic_usage.html#eventlet.spawn" title="eventlet.spawn"><code class="xref py py-func docutils literal"><span class="pre">eventlet.spawn()</span></code></a>, if you need to pass special
build flags to some set of builds, these can be passed as either positional or
keyword arguments:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">builder</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">upstream</span><span class="p">,</span> <span class="n">cflags</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="n">linkflags</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">):</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">builder</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">upstream</span><span class="p">,</span> <span class="n">cflags</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="n">linkflags</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">):</span>
<span class="o">...</span>
<span class="n">pool</span><span class="o">.</span><span class="n">spawn</span><span class="p">(</span><span class="s2">&quot;d&quot;</span><span class="p">,</span> <span class="p">(</span><span class="s2">&quot;b&quot;</span><span class="p">,</span> <span class="s2">&quot;c&quot;</span><span class="p">),</span> <span class="n">builder</span><span class="p">,</span> <span class="s2">&quot;-o2&quot;</span><span class="p">)</span>
@@ -160,7 +161,7 @@ keyword arguments:</p>
<p>However, if the arguments to each builder() call are uniform (as in the
original example), you could alternatively build a dict of the dependencies
and call <a class="reference internal" href="#eventlet.dagpool.DAGPool.spawn_many" title="eventlet.dagpool.DAGPool.spawn_many"><code class="xref py py-meth docutils literal"><span class="pre">spawn_many()</span></code></a>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">deps</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="n">d</span><span class="o">=</span><span class="p">(</span><span class="s2">&quot;b&quot;</span><span class="p">,</span> <span class="s2">&quot;c&quot;</span><span class="p">),</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">deps</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="n">d</span><span class="o">=</span><span class="p">(</span><span class="s2">&quot;b&quot;</span><span class="p">,</span> <span class="s2">&quot;c&quot;</span><span class="p">),</span>
<span class="n">e</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;c&quot;</span><span class="p">],</span>
<span class="n">b</span><span class="o">=</span><span class="p">(</span><span class="s2">&quot;a&quot;</span><span class="p">,</span> <span class="s2">&quot;zlib&quot;</span><span class="p">),</span>
<span class="n">c</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;zlib&quot;</span><span class="p">],</span>
@@ -173,32 +174,32 @@ for any of the build greenthreads) in any of several ways.</p>
<p><a class="reference internal" href="#eventlet.dagpool.DAGPool.waitall" title="eventlet.dagpool.DAGPool.waitall"><code class="xref py py-meth docutils literal"><span class="pre">pool.waitall()</span></code></a> waits until the last of the spawned
greenthreads has completed, and returns a dict containing results for <em>all</em> of
them:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">final</span> <span class="o">=</span> <span class="n">pool</span><span class="o">.</span><span class="n">waitall</span><span class="p">()</span>
<span class="k">print</span><span class="p">(</span><span class="s2">&quot;for d: {0}&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">final</span><span class="p">[</span><span class="s2">&quot;d&quot;</span><span class="p">]))</span>
<span class="k">print</span><span class="p">(</span><span class="s2">&quot;for e: {0}&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">final</span><span class="p">[</span><span class="s2">&quot;e&quot;</span><span class="p">]))</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">final</span> <span class="o">=</span> <span class="n">pool</span><span class="o">.</span><span class="n">waitall</span><span class="p">()</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;for d: </span><span class="si">{0}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">final</span><span class="p">[</span><span class="s2">&quot;d&quot;</span><span class="p">]))</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;for e: </span><span class="si">{0}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">final</span><span class="p">[</span><span class="s2">&quot;e&quot;</span><span class="p">]))</span>
</pre></div>
</div>
<p>waitall() is an alias for <a class="reference internal" href="#eventlet.dagpool.DAGPool.wait" title="eventlet.dagpool.DAGPool.wait"><code class="xref py py-meth docutils literal"><span class="pre">wait()</span></code></a> with no arguments:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">final</span> <span class="o">=</span> <span class="n">pool</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>
<span class="k">print</span><span class="p">(</span><span class="s2">&quot;for d: {0}&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">final</span><span class="p">[</span><span class="s2">&quot;d&quot;</span><span class="p">]))</span>
<span class="k">print</span><span class="p">(</span><span class="s2">&quot;for e: {0}&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">final</span><span class="p">[</span><span class="s2">&quot;e&quot;</span><span class="p">]))</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">final</span> <span class="o">=</span> <span class="n">pool</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;for d: </span><span class="si">{0}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">final</span><span class="p">[</span><span class="s2">&quot;d&quot;</span><span class="p">]))</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;for e: </span><span class="si">{0}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">final</span><span class="p">[</span><span class="s2">&quot;e&quot;</span><span class="p">]))</span>
</pre></div>
</div>
<p>Or you can specifically wait for only the final programs:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">final</span> <span class="o">=</span> <span class="n">pool</span><span class="o">.</span><span class="n">wait</span><span class="p">([</span><span class="s2">&quot;d&quot;</span><span class="p">,</span> <span class="s2">&quot;e&quot;</span><span class="p">])</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">final</span> <span class="o">=</span> <span class="n">pool</span><span class="o">.</span><span class="n">wait</span><span class="p">([</span><span class="s2">&quot;d&quot;</span><span class="p">,</span> <span class="s2">&quot;e&quot;</span><span class="p">])</span>
</pre></div>
</div>
<p>The returned dict will contain only the specified keys. The keys may be passed
into wait() from any iterable, including a generator.</p>
<p>You can wait for any specified set of greenthreads; they need not be
topologically last:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c1"># returns as soon as both a and zlib have returned results, regardless of</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="c1"># returns as soon as both a and zlib have returned results, regardless of</span>
<span class="c1"># what else is still running</span>
<span class="n">leaves</span> <span class="o">=</span> <span class="n">pool</span><span class="o">.</span><span class="n">wait</span><span class="p">([</span><span class="s2">&quot;a&quot;</span><span class="p">,</span> <span class="s2">&quot;zlib&quot;</span><span class="p">])</span>
</pre></div>
</div>
<p>Suppose you want to wait specifically for just <em>one</em> of the final programs:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">final</span> <span class="o">=</span> <span class="n">pool</span><span class="o">.</span><span class="n">wait</span><span class="p">([</span><span class="s2">&quot;d&quot;</span><span class="p">])</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">final</span> <span class="o">=</span> <span class="n">pool</span><span class="o">.</span><span class="n">wait</span><span class="p">([</span><span class="s2">&quot;d&quot;</span><span class="p">])</span>
<span class="n">dprog</span> <span class="o">=</span> <span class="n">final</span><span class="p">[</span><span class="s2">&quot;d&quot;</span><span class="p">]</span>
</pre></div>
</div>
@@ -206,20 +207,20 @@ topologically last:</p>
regardless of whether greenthread e has finished.</p>
<p><a class="reference internal" href="#eventlet.dagpool.DAGPool.__getitem__" title="eventlet.dagpool.DAGPool.__getitem__"><code class="xref py py-meth docutils literal"><span class="pre">__getitem()__</span></code></a> is shorthand for
obtaining a single result:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c1"># waits until greenthread d returns its result</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="c1"># waits until greenthread d returns its result</span>
<span class="n">dprog</span> <span class="o">=</span> <span class="n">pool</span><span class="p">[</span><span class="s2">&quot;d&quot;</span><span class="p">]</span>
</pre></div>
</div>
<p>In contrast, <a class="reference internal" href="#eventlet.dagpool.DAGPool.get" title="eventlet.dagpool.DAGPool.get"><code class="xref py py-meth docutils literal"><span class="pre">get()</span></code></a> returns immediately,
whether or not a result is ready:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c1"># returns immediately</span>
<span class="k">if</span> <span class="n">pool</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;d&quot;</span><span class="p">)</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="c1"># returns immediately</span>
<span class="k">if</span> <span class="n">pool</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;d&quot;</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="o">...</span>
</pre></div>
</div>
<p>Of course, your greenthread might not include an explicit return statement and
hence might implicitly return None. You might have to test some other value.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c1"># returns immediately</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="c1"># returns immediately</span>
<span class="k">if</span> <span class="n">pool</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;d&quot;</span><span class="p">,</span> <span class="s2">&quot;notdone&quot;</span><span class="p">)</span> <span class="o">==</span> <span class="s2">&quot;notdone&quot;</span><span class="p">:</span>
<span class="o">...</span>
</pre></div>
@@ -227,17 +228,17 @@ hence might implicitly return None. You might have to test some other value.</p>
<p>Suppose you want to process each of the final programs in some way (upload
it?), but you don&#8217;t want to have to wait until they&#8217;ve both finished. You
don&#8217;t have to poll get() calls &#8211; use <a class="reference internal" href="#eventlet.dagpool.DAGPool.wait_each" title="eventlet.dagpool.DAGPool.wait_each"><code class="xref py py-meth docutils literal"><span class="pre">wait_each()</span></code></a>:</p>
<div class="highlight-python"><div class="highlight"><pre>for key, result in pool.wait_each([&quot;d&quot;, &quot;e&quot;]):
# key will be d or e, in completion order
# process result...
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">result</span> <span class="ow">in</span> <span class="n">pool</span><span class="o">.</span><span class="n">wait_each</span><span class="p">([</span><span class="s2">&quot;d&quot;</span><span class="p">,</span> <span class="s2">&quot;e&quot;</span><span class="p">]):</span>
<span class="c1"># key will be d or e, in completion order</span>
<span class="c1"># process result...</span>
</pre></div>
</div>
<p>As with <a class="reference internal" href="#eventlet.dagpool.DAGPool.wait" title="eventlet.dagpool.DAGPool.wait"><code class="xref py py-meth docutils literal"><span class="pre">wait()</span></code></a>, if you omit the
argument to wait_each(), it delivers results for all the greenthreads of which
it&#8217;s aware:</p>
<div class="highlight-python"><div class="highlight"><pre>for key, result in pool.wait_each():
# key will be a, zlib, b, c, d, e, in whatever order each completes
# process its result...
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">result</span> <span class="ow">in</span> <span class="n">pool</span><span class="o">.</span><span class="n">wait_each</span><span class="p">():</span>
<span class="c1"># key will be a, zlib, b, c, d, e, in whatever order each completes</span>
<span class="c1"># process its result...</span>
</pre></div>
</div>
</div>
@@ -248,54 +249,54 @@ the dependencies shown above. To your consternation, your <a class="reference in
is stuck!</p>
<p>You could change waitall() to <a class="reference internal" href="#eventlet.dagpool.DAGPool.wait_each" title="eventlet.dagpool.DAGPool.wait_each"><code class="xref py py-meth docutils literal"><span class="pre">wait_each()</span></code></a>, and print each key as it becomes
available:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">result</span> <span class="ow">in</span> <span class="n">pool</span><span class="o">.</span><span class="n">wait_each</span><span class="p">():</span>
<span class="k">print</span><span class="p">(</span><span class="s2">&quot;got result for {0}&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">key</span><span class="p">))</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">result</span> <span class="ow">in</span> <span class="n">pool</span><span class="o">.</span><span class="n">wait_each</span><span class="p">():</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;got result for </span><span class="si">{0}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">key</span><span class="p">))</span>
<span class="c1"># ... process ...</span>
</pre></div>
</div>
<p>Once the build for a has completed, this produces:</p>
<div class="highlight-python"><div class="highlight"><pre>got result for a
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">got</span> <span class="n">result</span> <span class="k">for</span> <span class="n">a</span>
</pre></div>
</div>
<p>and then stops. Hmm!</p>
<p>You can check the number of <a class="reference internal" href="#eventlet.dagpool.DAGPool.running" title="eventlet.dagpool.DAGPool.running"><code class="xref py py-meth docutils literal"><span class="pre">running</span></code></a>
greenthreads:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="k">print</span><span class="p">(</span><span class="n">pool</span><span class="o">.</span><span class="n">running</span><span class="p">())</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">pool</span><span class="o">.</span><span class="n">running</span><span class="p">())</span>
<span class="go">4</span>
</pre></div>
</div>
<p>and the number of <a class="reference internal" href="#eventlet.dagpool.DAGPool.waiting" title="eventlet.dagpool.DAGPool.waiting"><code class="xref py py-meth docutils literal"><span class="pre">waiting</span></code></a>
greenthreads:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="k">print</span><span class="p">(</span><span class="n">pool</span><span class="o">.</span><span class="n">waiting</span><span class="p">())</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">pool</span><span class="o">.</span><span class="n">waiting</span><span class="p">())</span>
<span class="go">4</span>
</pre></div>
</div>
<p>It&#8217;s often more informative to ask <em>which</em> greenthreads are <a class="reference internal" href="#eventlet.dagpool.DAGPool.running_keys" title="eventlet.dagpool.DAGPool.running_keys"><code class="xref py py-meth docutils literal"><span class="pre">still</span>
<span class="pre">running</span></code></a>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="k">print</span><span class="p">(</span><span class="n">pool</span><span class="o">.</span><span class="n">running_keys</span><span class="p">())</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">pool</span><span class="o">.</span><span class="n">running_keys</span><span class="p">())</span>
<span class="go">(&#39;c&#39;, &#39;b&#39;, &#39;e&#39;, &#39;d&#39;)</span>
</pre></div>
</div>
<p>but in this case, we already know a has completed.</p>
<p>We can ask for all available results:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="k">print</span><span class="p">(</span><span class="n">pool</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">pool</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span>
<span class="go">(&#39;a&#39;,)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">print</span><span class="p">(</span><span class="n">pool</span><span class="o">.</span><span class="n">items</span><span class="p">())</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">pool</span><span class="o">.</span><span class="n">items</span><span class="p">())</span>
<span class="go">((&#39;a&#39;, result_from_a),)</span>
</pre></div>
</div>
<p>The <a class="reference internal" href="#eventlet.dagpool.DAGPool.keys" title="eventlet.dagpool.DAGPool.keys"><code class="xref py py-meth docutils literal"><span class="pre">keys()</span></code></a> and <a class="reference internal" href="#eventlet.dagpool.DAGPool.items" title="eventlet.dagpool.DAGPool.items"><code class="xref py py-meth docutils literal"><span class="pre">items()</span></code></a> methods only return keys and items for
which results are actually available, reflecting the underlying dict.</p>
<p>But what&#8217;s blocking the works? What are we <a class="reference internal" href="#eventlet.dagpool.DAGPool.waiting_for" title="eventlet.dagpool.DAGPool.waiting_for"><code class="xref py py-meth docutils literal"><span class="pre">waiting</span> <span class="pre">for</span></code></a>?</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="k">print</span><span class="p">(</span><span class="n">pool</span><span class="o">.</span><span class="n">waiting_for</span><span class="p">(</span><span class="s2">&quot;d&quot;</span><span class="p">))</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">pool</span><span class="o">.</span><span class="n">waiting_for</span><span class="p">(</span><span class="s2">&quot;d&quot;</span><span class="p">))</span>
<span class="go">set([&#39;c&#39;, &#39;b&#39;])</span>
</pre></div>
</div>
<p>(waiting_for()&#8217;s optional argument is a <em>single</em> key.)</p>
<p>That doesn&#8217;t help much yet...</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="k">print</span><span class="p">(</span><span class="n">pool</span><span class="o">.</span><span class="n">waiting_for</span><span class="p">(</span><span class="s2">&quot;b&quot;</span><span class="p">))</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">pool</span><span class="o">.</span><span class="n">waiting_for</span><span class="p">(</span><span class="s2">&quot;b&quot;</span><span class="p">))</span>
<span class="go">set([&#39;zlib&#39;])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">print</span><span class="p">(</span><span class="n">pool</span><span class="o">.</span><span class="n">waiting_for</span><span class="p">(</span><span class="s2">&quot;zlib&quot;</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">pool</span><span class="o">.</span><span class="n">waiting_for</span><span class="p">(</span><span class="s2">&quot;zlib&quot;</span><span class="p">))</span>
<span class="go">KeyError: &#39;zlib&#39;</span>
</pre></div>
</div>
@@ -304,14 +305,14 @@ configuring this DAGPool!</p>
<p>(For non-interactive use, it would be more informative to omit waiting_for()&#8217;s
argument. This usage returns a dict indicating, for each greenthread key,
which other keys it&#8217;s waiting for.)</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">pprint</span> <span class="kn">import</span> <span class="n">pprint</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">pprint</span> <span class="k">import</span> <span class="n">pprint</span>
<span class="n">pprint</span><span class="p">(</span><span class="n">pool</span><span class="o">.</span><span class="n">waiting_for</span><span class="p">())</span>
<span class="p">{</span><span class="s1">&#39;b&#39;</span><span class="p">:</span> <span class="nb">set</span><span class="p">([</span><span class="s1">&#39;zlib&#39;</span><span class="p">]),</span> <span class="s1">&#39;c&#39;</span><span class="p">:</span> <span class="nb">set</span><span class="p">([</span><span class="s1">&#39;zlib&#39;</span><span class="p">]),</span> <span class="s1">&#39;d&#39;</span><span class="p">:</span> <span class="nb">set</span><span class="p">([</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">]),</span> <span class="s1">&#39;e&#39;</span><span class="p">:</span> <span class="nb">set</span><span class="p">([</span><span class="s1">&#39;c&#39;</span><span class="p">])}</span>
</pre></div>
</div>
<p>In this case, a reasonable fix would be to spawn the zlib greenthread:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">pool</span><span class="o">.</span><span class="n">spawn</span><span class="p">(</span><span class="s2">&quot;zlib&quot;</span><span class="p">,</span> <span class="p">(),</span> <span class="n">builder</span><span class="p">)</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">pool</span><span class="o">.</span><span class="n">spawn</span><span class="p">(</span><span class="s2">&quot;zlib&quot;</span><span class="p">,</span> <span class="p">(),</span> <span class="n">builder</span><span class="p">)</span>
</pre></div>
</div>
<p>Even if this is the last method call on this DAGPool instance, it should
@@ -322,7 +323,7 @@ unblock all the rest of the DAGPool greenthreads.</p>
<p>If we happen to have zlib build results in hand already, though, we could
instead <a class="reference internal" href="#eventlet.dagpool.DAGPool.post" title="eventlet.dagpool.DAGPool.post"><code class="xref py py-meth docutils literal"><span class="pre">post()</span></code></a> that result instead of
rebuilding the library:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">pool</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="s2">&quot;zlib&quot;</span><span class="p">,</span> <span class="n">result_from_zlib</span><span class="p">)</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">pool</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="s2">&quot;zlib&quot;</span><span class="p">,</span> <span class="n">result_from_zlib</span><span class="p">)</span>
</pre></div>
</div>
<p>This, too, should unblock the rest of the DAGPool greenthreads.</p>
@@ -335,7 +336,7 @@ off rather than having to rebuild everything prior to that point.</p>
<p>You could iteratively <a class="reference internal" href="#eventlet.dagpool.DAGPool.post" title="eventlet.dagpool.DAGPool.post"><code class="xref py py-meth docutils literal"><span class="pre">post()</span></code></a> those
prior results into a new DAGPool instance; alternatively you can
<a class="reference internal" href="#eventlet.dagpool.DAGPool.__init__" title="eventlet.dagpool.DAGPool.__init__"><code class="xref py py-meth docutils literal"><span class="pre">preload</span></code></a> the <a class="reference internal" href="#eventlet.dagpool.DAGPool" title="eventlet.dagpool.DAGPool"><code class="xref py py-class docutils literal"><span class="pre">DAGPool</span></code></a> from an existing dict:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">pool</span> <span class="o">=</span> <span class="n">DAGPool</span><span class="p">(</span><span class="nb">dict</span><span class="p">(</span><span class="n">a</span><span class="o">=</span><span class="n">result_from_a</span><span class="p">,</span> <span class="n">zlib</span><span class="o">=</span><span class="n">result_from_zlib</span><span class="p">))</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">pool</span> <span class="o">=</span> <span class="n">DAGPool</span><span class="p">(</span><span class="nb">dict</span><span class="p">(</span><span class="n">a</span><span class="o">=</span><span class="n">result_from_a</span><span class="p">,</span> <span class="n">zlib</span><span class="o">=</span><span class="n">result_from_zlib</span><span class="p">))</span>
</pre></div>
</div>
<p>Any DAGPool greenthreads that depend on either a or zlib can immediately
@@ -347,8 +348,8 @@ consume those results.</p>
<p>But what if we spawn a zlib build that fails? Suppose the zlib greenthread
terminates with an exception? In that case none of b, c, d or e can proceed!
Nor do we want to wait forever for them.</p>
<div class="highlight-python"><div class="highlight"><pre>dprog = pool[&quot;d&quot;]
eventlet.dagpool.PropagateError: PropagateError(d): PropagateError: PropagateError(c): PropagateError: PropagateError(zlib): OriginalError
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">dprog</span> <span class="o">=</span> <span class="n">pool</span><span class="p">[</span><span class="s2">&quot;d&quot;</span><span class="p">]</span>
<span class="n">eventlet</span><span class="o">.</span><span class="n">dagpool</span><span class="o">.</span><span class="n">PropagateError</span><span class="p">:</span> <span class="n">PropagateError</span><span class="p">(</span><span class="n">d</span><span class="p">):</span> <span class="n">PropagateError</span><span class="p">:</span> <span class="n">PropagateError</span><span class="p">(</span><span class="n">c</span><span class="p">):</span> <span class="n">PropagateError</span><span class="p">:</span> <span class="n">PropagateError</span><span class="p">(</span><span class="n">zlib</span><span class="p">):</span> <span class="n">OriginalError</span>
</pre></div>
</div>
<p>DAGPool provides a <a class="reference internal" href="#eventlet.dagpool.PropagateError" title="eventlet.dagpool.PropagateError"><code class="xref py py-class docutils literal"><span class="pre">PropagateError</span></code></a>
@@ -359,8 +360,8 @@ greenthread and whose <em>exc</em> attribute is the exception that terminated it
This PropagateError is stored as the result from that greenthread.</p>
<p>Attempting to consume the result from a greenthread for which a PropagateError
was stored raises that PropagateError.</p>
<div class="highlight-python"><div class="highlight"><pre>pool[&quot;zlib&quot;]
eventlet.dagpool.PropagateError: PropagateError(zlib): OriginalError
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">pool</span><span class="p">[</span><span class="s2">&quot;zlib&quot;</span><span class="p">]</span>
<span class="n">eventlet</span><span class="o">.</span><span class="n">dagpool</span><span class="o">.</span><span class="n">PropagateError</span><span class="p">:</span> <span class="n">PropagateError</span><span class="p">(</span><span class="n">zlib</span><span class="p">):</span> <span class="n">OriginalError</span>
</pre></div>
</div>
<p>Thus, when greenthread c attempts to consume the result from zlib, the
@@ -375,7 +376,7 @@ whose <em>key</em> is d and whose <em>exc</em> is the PropagateError for c.</p>
PropagateError for d is raised.</p>
<p>You can programmatically chase the failure path to determine the original
failure if desired:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">orig_err</span> <span class="o">=</span> <span class="n">err</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">orig_err</span> <span class="o">=</span> <span class="n">err</span>
<span class="n">key</span> <span class="o">=</span> <span class="s2">&quot;unknown&quot;</span>
<span class="k">while</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">orig_err</span><span class="p">,</span> <span class="n">PropagateError</span><span class="p">):</span>
<span class="n">key</span> <span class="o">=</span> <span class="n">orig_err</span><span class="o">.</span><span class="n">key</span>
@@ -390,24 +391,24 @@ results that will never arrive.</p>
<p>However, it does make it difficult to obtain <em>partial</em> results for builds that
<em>did</em> succeed.</p>
<p>For that you can call <a class="reference internal" href="#eventlet.dagpool.DAGPool.wait_each_success" title="eventlet.dagpool.DAGPool.wait_each_success"><code class="xref py py-meth docutils literal"><span class="pre">wait_each_success()</span></code></a>:</p>
<div class="highlight-python"><div class="highlight"><pre>for key, result in pool.wait_each_success():
print(&quot;{0} succeeded&quot;.format(key))
# ... process result ...
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">result</span> <span class="ow">in</span> <span class="n">pool</span><span class="o">.</span><span class="n">wait_each_success</span><span class="p">():</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{0}</span><span class="s2"> succeeded&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">key</span><span class="p">))</span>
<span class="c1"># ... process result ...</span>
a succeeded
<span class="n">a</span> <span class="n">succeeded</span>
</pre></div>
</div>
<p>Another problem is that although five different greenthreads failed in the
example, we only see one chain of failures. You can enumerate the bad news
with <a class="reference internal" href="#eventlet.dagpool.DAGPool.wait_each_exception" title="eventlet.dagpool.DAGPool.wait_each_exception"><code class="xref py py-meth docutils literal"><span class="pre">wait_each_exception()</span></code></a>:</p>
<div class="highlight-python"><div class="highlight"><pre>for key, err in pool.wait_each_exception():
print(&quot;{0} failed with {1}&quot;.format(key, err.exc.__class__.__name__))
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">err</span> <span class="ow">in</span> <span class="n">pool</span><span class="o">.</span><span class="n">wait_each_exception</span><span class="p">():</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{0}</span><span class="s2"> failed with </span><span class="si">{1}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">err</span><span class="o">.</span><span class="n">exc</span><span class="o">.</span><span class="n">__class__</span><span class="o">.</span><span class="n">__name__</span><span class="p">))</span>
c failed with PropagateError
b failed with PropagateError
e failed with PropagateError
d failed with PropagateError
zlib failed with OriginalError
<span class="n">c</span> <span class="n">failed</span> <span class="k">with</span> <span class="n">PropagateError</span>
<span class="n">b</span> <span class="n">failed</span> <span class="k">with</span> <span class="n">PropagateError</span>
<span class="n">e</span> <span class="n">failed</span> <span class="k">with</span> <span class="n">PropagateError</span>
<span class="n">d</span> <span class="n">failed</span> <span class="k">with</span> <span class="n">PropagateError</span>
<span class="n">zlib</span> <span class="n">failed</span> <span class="k">with</span> <span class="n">OriginalError</span>
</pre></div>
</div>
<p>wait_each_exception() yields each PropagateError wrapper as if it were the
@@ -416,16 +417,16 @@ result, rather than raising it as an exception.</p>
<code class="code docutils literal"><span class="pre">err.__class__.__name__</span></code> is always PropagateError.</p>
<p>Both wait_each_success() and wait_each_exception() can accept an iterable of
keys to report:</p>
<div class="highlight-python"><div class="highlight"><pre>for key, result in pool.wait_each_success([&quot;d&quot;, &quot;e&quot;]):
print(&quot;{0} succeeded&quot;.format(key))
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">result</span> <span class="ow">in</span> <span class="n">pool</span><span class="o">.</span><span class="n">wait_each_success</span><span class="p">([</span><span class="s2">&quot;d&quot;</span><span class="p">,</span> <span class="s2">&quot;e&quot;</span><span class="p">]):</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{0}</span><span class="s2"> succeeded&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">key</span><span class="p">))</span>
(no output)
<span class="p">(</span><span class="n">no</span> <span class="n">output</span><span class="p">)</span>
for key, err in pool.wait_each_exception([&quot;d&quot;, &quot;e&quot;]):
print(&quot;{0} failed with {1}&quot;.format(key, err.exc.__class__.__name__))
<span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">err</span> <span class="ow">in</span> <span class="n">pool</span><span class="o">.</span><span class="n">wait_each_exception</span><span class="p">([</span><span class="s2">&quot;d&quot;</span><span class="p">,</span> <span class="s2">&quot;e&quot;</span><span class="p">]):</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{0}</span><span class="s2"> failed with </span><span class="si">{1}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">err</span><span class="o">.</span><span class="n">exc</span><span class="o">.</span><span class="n">__class__</span><span class="o">.</span><span class="n">__name__</span><span class="p">))</span>
e failed with PropagateError
d failed with PropagateError
<span class="n">e</span> <span class="n">failed</span> <span class="k">with</span> <span class="n">PropagateError</span>
<span class="n">d</span> <span class="n">failed</span> <span class="k">with</span> <span class="n">PropagateError</span>
</pre></div>
</div>
<p>Both wait_each_success() and wait_each_exception() must wait until the
@@ -667,9 +668,9 @@ each of the ready ones in arbitrary order before blocking again.</p>
its own greenthreads and one provided by a <a class="reference internal" href="#eventlet.dagpool.DAGPool.post" title="eventlet.dagpool.DAGPool.post"><code class="xref py py-meth docutils literal"><span class="pre">post()</span></code></a> call or <em>preload</em> data.</p>
<p>The wait_each() generator terminates (raises StopIteration) when all
specified keys have been delivered. Thus, typical usage might be:</p>
<div class="highlight-python"><div class="highlight"><pre>for key, value in dagpool.wait_each(keys):
# process this ready key and value
# continue processing now that we&#39;ve gotten values for all keys
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">dagpool</span><span class="o">.</span><span class="n">wait_each</span><span class="p">(</span><span class="n">keys</span><span class="p">):</span>
<span class="c1"># process this ready key and value</span>
<span class="c1"># continue processing now that we&#39;ve gotten values for all keys</span>
</pre></div>
</div>
<p>By implication, if you pass wait_each() an empty iterable of keys, it
@@ -789,21 +790,18 @@ PropagateError.</p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/modules/dagpool.txt"
<li><a href="../_sources/modules/dagpool.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">
<input type="text" name="q" />
<input type="submit" value="Go" />
<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>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
@@ -825,14 +823,14 @@ PropagateError.</p>
<li class="right" >
<a href="corolocal.html" title="corolocal Coroutine local storage"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" >Module Reference</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" >Module Reference</a> &#187;</li>
</ul>
</div>
<div class="footer" role="contentinfo">
&copy; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.5.
&#169; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

View File

@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>db_pool DBAPI 2 database connection pooling &mdash; Eventlet 0.20.0 documentation</title>
<title>db_pool DBAPI 2 database connection pooling &#8212; 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" />
@@ -17,14 +17,15 @@
VERSION: '0.20.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
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="top" title="Eventlet 0.20.0 documentation" href="../index.html" />
<link rel="up" title="Module Reference" href="../modules.html" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="next" title="event Cross-greenthread primitive" href="event.html" />
<link rel="prev" title="debug Debugging tools for Eventlet" href="debug.html" />
</head>
@@ -44,8 +45,8 @@
<li class="right" >
<a href="debug.html" title="debug Debugging tools for Eventlet"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" accesskey="U">Module Reference</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" accesskey="U">Module Reference</a> &#187;</li>
</ul>
</div>
@@ -59,16 +60,16 @@
<p>The db_pool module is useful for managing database connections. It provides three primary benefits: cooperative yielding during database operations, concurrency limiting to a database host, and connection reuse. db_pool is intended to be database-agnostic, compatible with any DB-API 2.0 database module.</p>
<p><em>It has currently been tested and used with both MySQLdb and psycopg2.</em></p>
<p>A ConnectionPool object represents a pool of connections open to a particular database. The arguments to the constructor include the database-software-specific module, the host name, and the credentials required for authentication. After construction, the ConnectionPool object decides when to create and sever connections with the target database.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">MySQLdb</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">MySQLdb</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cp</span> <span class="o">=</span> <span class="n">ConnectionPool</span><span class="p">(</span><span class="n">MySQLdb</span><span class="p">,</span> <span class="n">host</span><span class="o">=</span><span class="s1">&#39;localhost&#39;</span><span class="p">,</span> <span class="n">user</span><span class="o">=</span><span class="s1">&#39;root&#39;</span><span class="p">,</span> <span class="n">passwd</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>Once you have this pool object, you connect to the database by calling <code class="xref py py-meth docutils literal"><span class="pre">get()</span></code> on it:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">conn</span> <span class="o">=</span> <span class="n">cp</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">conn</span> <span class="o">=</span> <span class="n">cp</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
</pre></div>
</div>
<p>This call may either create a new connection, or reuse an existing open connection, depending on whether it has one open already or not. You can then use the connection object as normal. When done, you must return the connection to the pool:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">conn</span> <span class="o">=</span> <span class="n">cp</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">conn</span> <span class="o">=</span> <span class="n">cp</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">try</span><span class="p">:</span>
<span class="gp">... </span> <span class="n">result</span> <span class="o">=</span> <span class="n">conn</span><span class="o">.</span><span class="n">cursor</span><span class="p">()</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s1">&#39;SELECT NOW()&#39;</span><span class="p">)</span>
<span class="gp">... </span><span class="k">finally</span><span class="p">:</span>
@@ -94,7 +95,7 @@
<li>module : database module, e.g. MySQLdb. This is simply passed through to the ConnectionPool.</li>
<li>credentials : A dictionary, or dictionary-alike, mapping hostname to connection-argument-dictionary. This is used for the constructors of the ConnectionPool objects. Example:</li>
</ul>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">dc</span> <span class="o">=</span> <span class="n">DatabaseConnector</span><span class="p">(</span><span class="n">MySQLdb</span><span class="p">,</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">dc</span> <span class="o">=</span> <span class="n">DatabaseConnector</span><span class="p">(</span><span class="n">MySQLdb</span><span class="p">,</span>
<span class="gp">... </span> <span class="p">{</span><span class="s1">&#39;db.internal.example.com&#39;</span><span class="p">:</span> <span class="p">{</span><span class="s1">&#39;user&#39;</span><span class="p">:</span> <span class="s1">&#39;internal&#39;</span><span class="p">,</span> <span class="s1">&#39;passwd&#39;</span><span class="p">:</span> <span class="s1">&#39;s33kr1t&#39;</span><span class="p">},</span>
<span class="gp">... </span> <span class="s1">&#39;localhost&#39;</span><span class="p">:</span> <span class="p">{</span><span class="s1">&#39;user&#39;</span><span class="p">:</span> <span class="s1">&#39;root&#39;</span><span class="p">,</span> <span class="s1">&#39;passwd&#39;</span><span class="p">:</span> <span class="s1">&#39;&#39;</span><span class="p">}})</span>
</pre></div>
@@ -403,21 +404,18 @@ connections.</p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/modules/db_pool.txt"
<li><a href="../_sources/modules/db_pool.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">
<input type="text" name="q" />
<input type="submit" value="Go" />
<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>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
@@ -439,14 +437,14 @@ connections.</p>
<li class="right" >
<a href="debug.html" title="debug Debugging tools for Eventlet"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" >Module Reference</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" >Module Reference</a> &#187;</li>
</ul>
</div>
<div class="footer" role="contentinfo">
&copy; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.5.
&#169; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

View File

@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>debug Debugging tools for Eventlet &mdash; Eventlet 0.20.0 documentation</title>
<title>debug Debugging tools for Eventlet &#8212; 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" />
@@ -17,14 +17,15 @@
VERSION: '0.20.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
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="top" title="Eventlet 0.20.0 documentation" href="../index.html" />
<link rel="up" title="Module Reference" href="../modules.html" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="next" title="db_pool DBAPI 2 database connection pooling" href="db_pool.html" />
<link rel="prev" title="dagpool Dependency-Driven Greenthreads" href="dagpool.html" />
</head>
@@ -44,8 +45,8 @@
<li class="right" >
<a href="dagpool.html" title="dagpool Dependency-Driven Greenthreads"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" accesskey="U">Module Reference</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" accesskey="U">Module Reference</a> &#187;</li>
</ul>
</div>
@@ -142,7 +143,7 @@ greenlet is resumed. Therefore, any code that runs for a long
time without yielding to the hub will get interrupted by the
blocking detector (don&#8217;t use it in production!).</p>
<p>The <em>resolution</em> argument governs how long the SIGALARM timeout
waits in seconds. The implementation uses <a class="reference external" href="http://docs.python.org/library/signal.html#signal.setitimer" title="(in Python v2.7)"><code class="xref py py-func docutils literal"><span class="pre">signal.setitimer()</span></code></a>
waits in seconds. The implementation uses <a class="reference external" href="https://docs.python.org/2/library/signal.html#signal.setitimer" title="(in Python v2.7)"><code class="xref py py-func docutils literal"><span class="pre">signal.setitimer()</span></code></a>
and can be specified as a floating-point value.
The shorter the resolution, the greater the chance of false
positives.</p>
@@ -165,21 +166,18 @@ positives.</p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/modules/debug.txt"
<li><a href="../_sources/modules/debug.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">
<input type="text" name="q" />
<input type="submit" value="Go" />
<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>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
@@ -201,14 +199,14 @@ positives.</p>
<li class="right" >
<a href="dagpool.html" title="dagpool Dependency-Driven Greenthreads"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" >Module Reference</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" >Module Reference</a> &#187;</li>
</ul>
</div>
<div class="footer" role="contentinfo">
&copy; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.5.
&#169; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

View File

@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>event Cross-greenthread primitive &mdash; Eventlet 0.20.0 documentation</title>
<title>event Cross-greenthread primitive &#8212; 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" />
@@ -17,14 +17,15 @@
VERSION: '0.20.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
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="top" title="Eventlet 0.20.0 documentation" href="../index.html" />
<link rel="up" title="Module Reference" href="../modules.html" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="next" title="greenpool Green Thread Pools" href="greenpool.html" />
<link rel="prev" title="db_pool DBAPI 2 database connection pooling" href="db_pool.html" />
</head>
@@ -44,8 +45,8 @@
<li class="right" >
<a href="db_pool.html" title="db_pool DBAPI 2 database connection pooling"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" accesskey="U">Module Reference</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" accesskey="U">Module Reference</a> &#187;</li>
</ul>
</div>
@@ -71,7 +72,7 @@ in two important ways:</p>
are the basis for how
<a class="reference internal" href="greenthread.html#eventlet.greenthread.GreenThread.wait" title="eventlet.greenthread.GreenThread.wait"><code class="xref py py-meth docutils literal"><span class="pre">GreenThread.wait()</span></code></a>
is implemented.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">eventlet</span> <span class="kn">import</span> <span class="n">event</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">eventlet</span> <span class="k">import</span> <span class="n">event</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">eventlet</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">evt</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">def</span> <span class="nf">baz</span><span class="p">(</span><span class="n">b</span><span class="p">):</span>
@@ -97,13 +98,13 @@ and then you can <a class="reference internal" href="#eventlet.event.Event.wait"
<code class="descname">send</code><span class="sig-paren">(</span><em>result=None</em>, <em>exc=None</em><span class="sig-paren">)</span><a class="headerlink" href="#eventlet.event.Event.send" title="Permalink to this definition"></a></dt>
<dd><p>Makes arrangements for the waiters to be woken with the
result and then returns immediately to the parent.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">eventlet</span> <span class="kn">import</span> <span class="n">event</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">eventlet</span> <span class="k">import</span> <span class="n">event</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">eventlet</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">evt</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">def</span> <span class="nf">waiter</span><span class="p">():</span>
<span class="gp">... </span> <span class="k">print</span><span class="p">(</span><span class="s1">&#39;about to wait&#39;</span><span class="p">)</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;about to wait&#39;</span><span class="p">)</span>
<span class="gp">... </span> <span class="n">result</span> <span class="o">=</span> <span class="n">evt</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>
<span class="gp">... </span> <span class="k">print</span><span class="p">(</span><span class="s1">&#39;waited for {0}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">result</span><span class="p">))</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;waited for </span><span class="si">{0}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">result</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_</span> <span class="o">=</span> <span class="n">eventlet</span><span class="o">.</span><span class="n">spawn</span><span class="p">(</span><span class="n">waiter</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">eventlet</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="go">about to wait</span>
@@ -113,7 +114,7 @@ result and then returns immediately to the parent.</p>
</pre></div>
</div>
<p>It is an error to call <a class="reference internal" href="#eventlet.event.Event.send" title="eventlet.event.Event.send"><code class="xref py py-meth docutils literal"><span class="pre">send()</span></code></a> multiple times on the same event.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">evt</span><span class="o">.</span><span class="n">send</span><span class="p">(</span><span class="s1">&#39;whoops&#39;</span><span class="p">)</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">evt</span><span class="o">.</span><span class="n">send</span><span class="p">(</span><span class="s1">&#39;whoops&#39;</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">AssertionError</span>: <span class="n">Trying to re-send() an already-triggered event.</span>
@@ -130,7 +131,7 @@ result and then returns immediately to the parent.</p>
to <code class="docutils literal"><span class="pre">raise</span></code>. If a single exception object is passed in, it
will be re-raised when <a class="reference internal" href="#eventlet.event.Event.wait" title="eventlet.event.Event.wait"><code class="xref py py-meth docutils literal"><span class="pre">wait()</span></code></a> is called, generating a
new stacktrace.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">eventlet</span> <span class="kn">import</span> <span class="n">event</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">eventlet</span> <span class="k">import</span> <span class="n">event</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">evt</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">evt</span><span class="o">.</span><span class="n">send_exception</span><span class="p">(</span><span class="ne">RuntimeError</span><span class="p">())</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">evt</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>
@@ -142,8 +143,8 @@ new stacktrace.</p>
</pre></div>
</div>
<p>If it&#8217;s important to preserve the entire original stack trace,
you must pass in the entire <a class="reference external" href="http://docs.python.org/library/sys.html#sys.exc_info" title="(in Python v2.7)"><code class="xref py py-func docutils literal"><span class="pre">sys.exc_info()</span></code></a> tuple.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">sys</span>
you must pass in the entire <a class="reference external" href="https://docs.python.org/2/library/sys.html#sys.exc_info" title="(in Python v2.7)"><code class="xref py py-func docutils literal"><span class="pre">sys.exc_info()</span></code></a> tuple.</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">sys</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">evt</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">try</span><span class="p">:</span>
<span class="gp">... </span> <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">()</span>
@@ -161,7 +162,7 @@ you must pass in the entire <a class="reference external" href="http://docs.pyth
</div>
<p>Note that doing so stores a traceback object directly on the
Event object, which may cause reference cycles. See the
<a class="reference external" href="http://docs.python.org/library/sys.html#sys.exc_info" title="(in Python v2.7)"><code class="xref py py-func docutils literal"><span class="pre">sys.exc_info()</span></code></a> documentation.</p>
<a class="reference external" href="https://docs.python.org/2/library/sys.html#sys.exc_info" title="(in Python v2.7)"><code class="xref py py-func docutils literal"><span class="pre">sys.exc_info()</span></code></a> documentation.</p>
</dd></dl>
<dl class="method">
@@ -170,12 +171,12 @@ Event object, which may cause reference cycles. See the
<dd><p>Wait until another coroutine calls <a class="reference internal" href="#eventlet.event.Event.send" title="eventlet.event.Event.send"><code class="xref py py-meth docutils literal"><span class="pre">send()</span></code></a>.
Returns the value the other coroutine passed to
<a class="reference internal" href="#eventlet.event.Event.send" title="eventlet.event.Event.send"><code class="xref py py-meth docutils literal"><span class="pre">send()</span></code></a>.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">eventlet</span> <span class="kn">import</span> <span class="n">event</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">eventlet</span> <span class="k">import</span> <span class="n">event</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">eventlet</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">evt</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">def</span> <span class="nf">wait_on</span><span class="p">():</span>
<span class="gp">... </span> <span class="n">retval</span> <span class="o">=</span> <span class="n">evt</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>
<span class="gp">... </span> <span class="k">print</span><span class="p">(</span><span class="s2">&quot;waited for {0}&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">retval</span><span class="p">))</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;waited for </span><span class="si">{0}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">retval</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_</span> <span class="o">=</span> <span class="n">eventlet</span><span class="o">.</span><span class="n">spawn</span><span class="p">(</span><span class="n">wait_on</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">evt</span><span class="o">.</span><span class="n">send</span><span class="p">(</span><span class="s1">&#39;result&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">eventlet</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
@@ -184,7 +185,7 @@ Returns the value the other coroutine passed to
</div>
<p>Returns immediately if the event has already
occurred.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">evt</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">evt</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>
<span class="go">&#39;result&#39;</span>
</pre></div>
</div>
@@ -209,21 +210,18 @@ occurred.</p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/modules/event.txt"
<li><a href="../_sources/modules/event.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">
<input type="text" name="q" />
<input type="submit" value="Go" />
<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>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
@@ -245,14 +243,14 @@ occurred.</p>
<li class="right" >
<a href="db_pool.html" title="db_pool DBAPI 2 database connection pooling"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" >Module Reference</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" >Module Reference</a> &#187;</li>
</ul>
</div>
<div class="footer" role="contentinfo">
&copy; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.5.
&#169; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

View File

@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>greenpool Green Thread Pools &mdash; Eventlet 0.20.0 documentation</title>
<title>greenpool Green Thread Pools &#8212; 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" />
@@ -17,14 +17,15 @@
VERSION: '0.20.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
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="top" title="Eventlet 0.20.0 documentation" href="../index.html" />
<link rel="up" title="Module Reference" href="../modules.html" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="next" title="greenthread Green Thread Implementation" href="greenthread.html" />
<link rel="prev" title="event Cross-greenthread primitive" href="event.html" />
</head>
@@ -44,8 +45,8 @@
<li class="right" >
<a href="event.html" title="event Cross-greenthread primitive"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" accesskey="U">Module Reference</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" accesskey="U">Module Reference</a> &#187;</li>
</ul>
</div>
@@ -71,14 +72,14 @@ block the calling greenthread until a slot becomes available.</p>
<dl class="method">
<dt id="eventlet.greenpool.GreenPool.imap">
<code class="descname">imap</code><span class="sig-paren">(</span><em>function</em>, <em>*iterables</em><span class="sig-paren">)</span><a class="headerlink" href="#eventlet.greenpool.GreenPool.imap" title="Permalink to this definition"></a></dt>
<dd><p>This is the same as <a class="reference external" href="http://docs.python.org/library/itertools.html#itertools.imap" title="(in Python v2.7)"><code class="xref py py-func docutils literal"><span class="pre">itertools.imap()</span></code></a>, and has the same
<dd><p>This is the same as <a class="reference external" href="https://docs.python.org/2/library/itertools.html#itertools.imap" title="(in Python v2.7)"><code class="xref py py-func docutils literal"><span class="pre">itertools.imap()</span></code></a>, and has the same
concurrency and memory behavior as <a class="reference internal" href="#eventlet.greenpool.GreenPool.starmap" title="eventlet.greenpool.GreenPool.starmap"><code class="xref py py-meth docutils literal"><span class="pre">starmap()</span></code></a>.</p>
<p>It&#8217;s quite convenient for, e.g., farming out jobs from a file:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">worker</span><span class="p">(</span><span class="n">line</span><span class="p">):</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">worker</span><span class="p">(</span><span class="n">line</span><span class="p">):</span>
<span class="k">return</span> <span class="n">do_something</span><span class="p">(</span><span class="n">line</span><span class="p">)</span>
<span class="n">pool</span> <span class="o">=</span> <span class="n">GreenPool</span><span class="p">()</span>
<span class="k">for</span> <span class="n">result</span> <span class="ow">in</span> <span class="n">pool</span><span class="o">.</span><span class="n">imap</span><span class="p">(</span><span class="n">worker</span><span class="p">,</span> <span class="nb">open</span><span class="p">(</span><span class="s2">&quot;filename&quot;</span><span class="p">,</span> <span class="s1">&#39;r&#39;</span><span class="p">)):</span>
<span class="k">print</span><span class="p">(</span><span class="n">result</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">result</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>
@@ -125,7 +126,7 @@ None; the results of <em>function</em> are not retrievable.</p>
<dl class="method">
<dt id="eventlet.greenpool.GreenPool.starmap">
<code class="descname">starmap</code><span class="sig-paren">(</span><em>function</em>, <em>iterable</em><span class="sig-paren">)</span><a class="headerlink" href="#eventlet.greenpool.GreenPool.starmap" title="Permalink to this definition"></a></dt>
<dd><p>This is the same as <a class="reference external" href="http://docs.python.org/library/itertools.html#itertools.starmap" title="(in Python v2.7)"><code class="xref py py-func docutils literal"><span class="pre">itertools.starmap()</span></code></a>, except that <em>func</em> is
<dd><p>This is the same as <a class="reference external" href="https://docs.python.org/2/library/itertools.html#itertools.starmap" title="(in Python v2.7)"><code class="xref py py-func docutils literal"><span class="pre">itertools.starmap()</span></code></a>, except that <em>func</em> is
executed in a separate green thread for each item, with the concurrency
limited by the pool&#8217;s size. In operation, starmap consumes a constant
amount of memory, proportional to the size of the pool, and is thus
@@ -192,21 +193,18 @@ iterating over the GreenPile object.</p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/modules/greenpool.txt"
<li><a href="../_sources/modules/greenpool.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">
<input type="text" name="q" />
<input type="submit" value="Go" />
<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>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
@@ -228,14 +226,14 @@ iterating over the GreenPile object.</p>
<li class="right" >
<a href="event.html" title="event Cross-greenthread primitive"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" >Module Reference</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" >Module Reference</a> &#187;</li>
</ul>
</div>
<div class="footer" role="contentinfo">
&copy; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.5.
&#169; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

View File

@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>greenthread Green Thread Implementation &mdash; Eventlet 0.20.0 documentation</title>
<title>greenthread Green Thread Implementation &#8212; 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" />
@@ -17,14 +17,15 @@
VERSION: '0.20.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
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="top" title="Eventlet 0.20.0 documentation" href="../index.html" />
<link rel="up" title="Module Reference" href="../modules.html" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="next" title="pools - Generic pools of resources" href="pools.html" />
<link rel="prev" title="greenpool Green Thread Pools" href="greenpool.html" />
</head>
@@ -44,8 +45,8 @@
<li class="right" >
<a href="greenpool.html" title="greenpool Green Thread Pools"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" accesskey="U">Module Reference</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" accesskey="U">Module Reference</a> &#187;</li>
</ul>
</div>
@@ -167,7 +168,7 @@ to <code class="xref py py-class docutils literal"><span class="pre">greenlet.Gr
<code class="descname">link</code><span class="sig-paren">(</span><em>func</em>, <em>*curried_args</em>, <em>**curried_kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#eventlet.greenthread.GreenThread.link" title="Permalink to this definition"></a></dt>
<dd><p>Set up a function to be called with the results of the GreenThread.</p>
<p>The function must have the following signature:</p>
<div class="highlight-python"><div class="highlight"><pre>def func(gt, [curried args/kwargs]):
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">func</span><span class="p">(</span><span class="n">gt</span><span class="p">,</span> <span class="p">[</span><span class="n">curried</span> <span class="n">args</span><span class="o">/</span><span class="n">kwargs</span><span class="p">]):</span>
</pre></div>
</div>
<p>When the GreenThread finishes its run, it calls <em>func</em> with itself
@@ -216,21 +217,18 @@ greenthread module).</p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/modules/greenthread.txt"
<li><a href="../_sources/modules/greenthread.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">
<input type="text" name="q" />
<input type="submit" value="Go" />
<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>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
@@ -252,14 +250,14 @@ greenthread module).</p>
<li class="right" >
<a href="greenpool.html" title="greenpool Green Thread Pools"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" >Module Reference</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" >Module Reference</a> &#187;</li>
</ul>
</div>
<div class="footer" role="contentinfo">
&copy; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.5.
&#169; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

View File

@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>pools - Generic pools of resources &mdash; Eventlet 0.20.0 documentation</title>
<title>pools - Generic pools of resources &#8212; 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" />
@@ -17,14 +17,15 @@
VERSION: '0.20.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
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="top" title="Eventlet 0.20.0 documentation" href="../index.html" />
<link rel="up" title="Module Reference" href="../modules.html" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="next" title="queue Queue class" href="queue.html" />
<link rel="prev" title="greenthread Green Thread Implementation" href="greenthread.html" />
</head>
@@ -44,8 +45,8 @@
<li class="right" >
<a href="greenthread.html" title="greenthread Green Thread Implementation"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" accesskey="U">Module Reference</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" accesskey="U">Module Reference</a> &#187;</li>
</ul>
</div>
@@ -64,29 +65,29 @@
subclassing. In either case you must provide a way to create
the resource.</p>
<p>When using <cite>create</cite> argument, pass a function with no arguments:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">http_pool</span> <span class="o">=</span> <span class="n">pools</span><span class="o">.</span><span class="n">Pool</span><span class="p">(</span><span class="n">create</span><span class="o">=</span><span class="n">httplib2</span><span class="o">.</span><span class="n">Http</span><span class="p">)</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">http_pool</span> <span class="o">=</span> <span class="n">pools</span><span class="o">.</span><span class="n">Pool</span><span class="p">(</span><span class="n">create</span><span class="o">=</span><span class="n">httplib2</span><span class="o">.</span><span class="n">Http</span><span class="p">)</span>
</pre></div>
</div>
<p>If you need to pass arguments, build a nullary function with either
<cite>lambda</cite> expression:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">http_pool</span> <span class="o">=</span> <span class="n">pools</span><span class="o">.</span><span class="n">Pool</span><span class="p">(</span><span class="n">create</span><span class="o">=</span><span class="k">lambda</span><span class="p">:</span> <span class="n">httplib2</span><span class="o">.</span><span class="n">Http</span><span class="p">(</span><span class="n">timeout</span><span class="o">=</span><span class="mi">90</span><span class="p">))</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">http_pool</span> <span class="o">=</span> <span class="n">pools</span><span class="o">.</span><span class="n">Pool</span><span class="p">(</span><span class="n">create</span><span class="o">=</span><span class="k">lambda</span><span class="p">:</span> <span class="n">httplib2</span><span class="o">.</span><span class="n">Http</span><span class="p">(</span><span class="n">timeout</span><span class="o">=</span><span class="mi">90</span><span class="p">))</span>
</pre></div>
</div>
<p>or <a class="reference external" href="http://docs.python.org/library/functools.html#functools.partial" title="(in Python v2.7)"><code class="xref py py-func docutils literal"><span class="pre">functools.partial()</span></code></a>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">functools</span> <span class="kn">import</span> <span class="n">partial</span>
<p>or <a class="reference external" href="https://docs.python.org/2/library/functools.html#functools.partial" title="(in Python v2.7)"><code class="xref py py-func docutils literal"><span class="pre">functools.partial()</span></code></a>:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">functools</span> <span class="k">import</span> <span class="n">partial</span>
<span class="n">http_pool</span> <span class="o">=</span> <span class="n">pools</span><span class="o">.</span><span class="n">Pool</span><span class="p">(</span><span class="n">create</span><span class="o">=</span><span class="n">partial</span><span class="p">(</span><span class="n">httplib2</span><span class="o">.</span><span class="n">Http</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="mi">90</span><span class="p">))</span>
</pre></div>
</div>
<p>When subclassing, define only the <a class="reference internal" href="#eventlet.pools.Pool.create" title="eventlet.pools.Pool.create"><code class="xref py py-meth docutils literal"><span class="pre">create()</span></code></a> method
to implement the desired resource:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">MyPool</span><span class="p">(</span><span class="n">pools</span><span class="o">.</span><span class="n">Pool</span><span class="p">):</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">MyPool</span><span class="p">(</span><span class="n">pools</span><span class="o">.</span><span class="n">Pool</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">create</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="n">MyObject</span><span class="p">()</span>
</pre></div>
</div>
<p>If using 2.5 or greater, the <a class="reference internal" href="#eventlet.pools.Pool.item" title="eventlet.pools.Pool.item"><code class="xref py py-meth docutils literal"><span class="pre">item()</span></code></a> method acts as a context manager;
that&#8217;s the best way to use it:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">with</span> <span class="n">mypool</span><span class="o">.</span><span class="n">item</span><span class="p">()</span> <span class="k">as</span> <span class="n">thing</span><span class="p">:</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">mypool</span><span class="o">.</span><span class="n">item</span><span class="p">()</span> <span class="k">as</span> <span class="n">thing</span><span class="p">:</span>
<span class="n">thing</span><span class="o">.</span><span class="n">dostuff</span><span class="p">()</span>
</pre></div>
</div>
@@ -133,10 +134,10 @@ cause the calling greenthread to block.</p>
<dt id="eventlet.pools.Pool.item">
<code class="descname">item</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#eventlet.pools.Pool.item" title="Permalink to this definition"></a></dt>
<dd><p>Get an object out of the pool, for use with with statement.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">eventlet</span> <span class="kn">import</span> <span class="n">pools</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">eventlet</span> <span class="k">import</span> <span class="n">pools</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pool</span> <span class="o">=</span> <span class="n">pools</span><span class="o">.</span><span class="n">TokenPool</span><span class="p">(</span><span class="n">max_size</span><span class="o">=</span><span class="mi">4</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">with</span> <span class="n">pool</span><span class="o">.</span><span class="n">item</span><span class="p">()</span> <span class="k">as</span> <span class="n">obj</span><span class="p">:</span>
<span class="gp">... </span> <span class="k">print</span><span class="p">(</span><span class="s2">&quot;got token&quot;</span><span class="p">)</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;got token&quot;</span><span class="p">)</span>
<span class="gp">...</span>
<span class="go">got token</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pool</span><span class="o">.</span><span class="n">free</span><span class="p">()</span>
@@ -196,21 +197,18 @@ limited resource.</p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/modules/pools.txt"
<li><a href="../_sources/modules/pools.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">
<input type="text" name="q" />
<input type="submit" value="Go" />
<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>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
@@ -232,14 +230,14 @@ limited resource.</p>
<li class="right" >
<a href="greenthread.html" title="greenthread Green Thread Implementation"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" >Module Reference</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" >Module Reference</a> &#187;</li>
</ul>
</div>
<div class="footer" role="contentinfo">
&copy; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.5.
&#169; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

View File

@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>queue Queue class &mdash; Eventlet 0.20.0 documentation</title>
<title>queue Queue class &#8212; 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" />
@@ -17,14 +17,15 @@
VERSION: '0.20.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
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="top" title="Eventlet 0.20.0 documentation" href="../index.html" />
<link rel="up" title="Module Reference" href="../modules.html" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="next" title="semaphore Semaphore classes" href="semaphore.html" />
<link rel="prev" title="pools - Generic pools of resources" href="pools.html" />
</head>
@@ -44,8 +45,8 @@
<li class="right" >
<a href="pools.html" title="pools - Generic pools of resources"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" accesskey="U">Module Reference</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" accesskey="U">Module Reference</a> &#187;</li>
</ul>
</div>
@@ -59,7 +60,7 @@
<p>Synchronized queues.</p>
<p>The <a class="reference internal" href="#module-eventlet.queue" title="eventlet.queue"><code class="xref py py-mod docutils literal"><span class="pre">eventlet.queue</span></code></a> module implements multi-producer, multi-consumer
queues that work across greenlets, with the API similar to the classes found in
the standard <a class="reference external" href="http://docs.python.org/library/queue.html#module-Queue" title="(in Python v2.7)"><code class="xref py py-mod docutils literal"><span class="pre">Queue</span></code></a> and <a class="reference external" href="http://docs.python.org/library/multiprocessing.html#multiprocessing.Queue" title="(in Python v2.7)"><code class="xref py py-class docutils literal"><span class="pre">multiprocessing</span></code></a>
the standard <a class="reference external" href="https://docs.python.org/2/library/queue.html#module-Queue" title="(in Python v2.7)"><code class="xref py py-mod docutils literal"><span class="pre">Queue</span></code></a> and <a class="reference external" href="https://docs.python.org/2/library/multiprocessing.html#multiprocessing.Queue" title="(in Python v2.7)"><code class="xref py py-class docutils literal"><span class="pre">multiprocessing</span></code></a>
modules.</p>
<p>A major difference is that queues in this module operate as channels when
initialized with <em>maxsize</em> of zero. In such case, both <code class="xref py py-meth docutils literal"><span class="pre">Queue.empty()</span></code>
@@ -238,21 +239,18 @@ items into the queue.</p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/modules/queue.txt"
<li><a href="../_sources/modules/queue.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">
<input type="text" name="q" />
<input type="submit" value="Go" />
<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>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
@@ -274,14 +272,14 @@ items into the queue.</p>
<li class="right" >
<a href="pools.html" title="pools - Generic pools of resources"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" >Module Reference</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" >Module Reference</a> &#187;</li>
</ul>
</div>
<div class="footer" role="contentinfo">
&copy; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.5.
&#169; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

View File

@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>semaphore Semaphore classes &mdash; Eventlet 0.20.0 documentation</title>
<title>semaphore Semaphore classes &#8212; 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" />
@@ -17,14 +17,15 @@
VERSION: '0.20.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
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="top" title="Eventlet 0.20.0 documentation" href="../index.html" />
<link rel="up" title="Module Reference" href="../modules.html" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="next" title="timeout Universal Timeouts" href="timeout.html" />
<link rel="prev" title="queue Queue class" href="queue.html" />
</head>
@@ -44,8 +45,8 @@
<li class="right" >
<a href="queue.html" title="queue Queue class"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" accesskey="U">Module Reference</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" accesskey="U">Module Reference</a> &#187;</li>
</ul>
</div>
@@ -64,16 +65,16 @@ Optionally initialize with a resource <em>count</em>, then <code class="xref py
<code class="xref py py-meth docutils literal"><span class="pre">release()</span></code> resources as needed. Attempting to <code class="xref py py-meth docutils literal"><span class="pre">acquire()</span></code> when
<em>count</em> is zero suspends the calling greenthread until <em>count</em> becomes
nonzero again.</p>
<p>This is API-compatible with <a class="reference external" href="http://docs.python.org/library/threading.html#threading.Semaphore" title="(in Python v2.7)"><code class="xref py py-class docutils literal"><span class="pre">threading.Semaphore</span></code></a>.</p>
<p>This is API-compatible with <a class="reference external" href="https://docs.python.org/2/library/threading.html#threading.Semaphore" title="(in Python v2.7)"><code class="xref py py-class docutils literal"><span class="pre">threading.Semaphore</span></code></a>.</p>
<p>It is a context manager, and thus can be used in a with block:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">sem</span> <span class="o">=</span> <span class="n">Semaphore</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">sem</span> <span class="o">=</span> <span class="n">Semaphore</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="k">with</span> <span class="n">sem</span><span class="p">:</span>
<span class="n">do_some_stuff</span><span class="p">()</span>
</pre></div>
</div>
<p>If not specified, <em>value</em> defaults to 1.</p>
<p>It is possible to limit acquire time:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">sem</span> <span class="o">=</span> <span class="n">Semaphore</span><span class="p">()</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">sem</span> <span class="o">=</span> <span class="n">Semaphore</span><span class="p">()</span>
<span class="n">ok</span> <span class="o">=</span> <span class="n">sem</span><span class="o">.</span><span class="n">acquire</span><span class="p">(</span><span class="n">timeout</span><span class="o">=</span><span class="mf">0.1</span><span class="p">)</span>
<span class="c1"># True if acquired, False if timed out.</span>
</pre></div>
@@ -167,13 +168,13 @@ and is ignored</p>
again. Attempting to <code class="xref py py-meth docutils literal"><span class="pre">release()</span></code> after <em>count</em> has reached <em>limit</em>
suspends the calling greenthread until <em>count</em> becomes less than <em>limit</em>
again.</p>
<p>This has the same API as <a class="reference external" href="http://docs.python.org/library/threading.html#threading.Semaphore" title="(in Python v2.7)"><code class="xref py py-class docutils literal"><span class="pre">threading.Semaphore</span></code></a>, though its
<p>This has the same API as <a class="reference external" href="https://docs.python.org/2/library/threading.html#threading.Semaphore" title="(in Python v2.7)"><code class="xref py py-class docutils literal"><span class="pre">threading.Semaphore</span></code></a>, though its
semantics and behavior differ subtly due to the upper limit on calls
to <code class="xref py py-meth docutils literal"><span class="pre">release()</span></code>. It is <strong>not</strong> compatible with
<code class="xref py py-class docutils literal"><span class="pre">threading.BoundedSemaphore</span></code> because it blocks when reaching <em>limit</em>
instead of raising a ValueError.</p>
<p>It is a context manager, and thus can be used in a with block:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">sem</span> <span class="o">=</span> <span class="n">CappedSemaphore</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">sem</span> <span class="o">=</span> <span class="n">CappedSemaphore</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="k">with</span> <span class="n">sem</span><span class="p">:</span>
<span class="n">do_some_stuff</span><span class="p">()</span>
</pre></div>
@@ -251,21 +252,18 @@ counter is greater than or equal to <em>limit</em>.</p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/modules/semaphore.txt"
<li><a href="../_sources/modules/semaphore.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">
<input type="text" name="q" />
<input type="submit" value="Go" />
<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>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
@@ -287,14 +285,14 @@ counter is greater than or equal to <em>limit</em>.</p>
<li class="right" >
<a href="queue.html" title="queue Queue class"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" >Module Reference</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" >Module Reference</a> &#187;</li>
</ul>
</div>
<div class="footer" role="contentinfo">
&copy; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.5.
&#169; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

View File

@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>timeout Universal Timeouts &mdash; Eventlet 0.20.0 documentation</title>
<title>timeout Universal Timeouts &#8212; 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" />
@@ -17,14 +17,15 @@
VERSION: '0.20.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
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="top" title="Eventlet 0.20.0 documentation" href="../index.html" />
<link rel="up" title="Module Reference" href="../modules.html" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="next" title="websocket Websocket Server" href="websocket.html" />
<link rel="prev" title="semaphore Semaphore classes" href="semaphore.html" />
</head>
@@ -44,8 +45,8 @@
<li class="right" >
<a href="semaphore.html" title="semaphore Semaphore classes"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" accesskey="U">Module Reference</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" accesskey="U">Module Reference</a> &#187;</li>
</ul>
</div>
@@ -60,7 +61,7 @@
<dt id="eventlet.timeout.Timeout">
<em class="property">class </em><code class="descclassname">eventlet.timeout.</code><code class="descname">Timeout</code><a class="headerlink" href="#eventlet.timeout.Timeout" title="Permalink to this definition"></a></dt>
<dd><p>Raises <em>exception</em> in the current greenthread after <em>timeout</em> seconds:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">timeout</span> <span class="o">=</span> <span class="n">Timeout</span><span class="p">(</span><span class="n">seconds</span><span class="p">,</span> <span class="n">exception</span><span class="p">)</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">timeout</span> <span class="o">=</span> <span class="n">Timeout</span><span class="p">(</span><span class="n">seconds</span><span class="p">,</span> <span class="n">exception</span><span class="p">)</span>
<span class="k">try</span><span class="p">:</span>
<span class="o">...</span> <span class="c1"># execution here is limited by timeout</span>
<span class="k">finally</span><span class="p">:</span>
@@ -69,7 +70,7 @@
</div>
<p>When <em>exception</em> is omitted or is <code class="docutils literal"><span class="pre">None</span></code>, the <code class="xref py py-class docutils literal"><span class="pre">Timeout</span></code> instance
itself is raised:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">Timeout</span><span class="p">(</span><span class="mf">0.1</span><span class="p">)</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Timeout</span><span class="p">(</span><span class="mf">0.1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">eventlet</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mf">0.2</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
@@ -77,7 +78,7 @@ itself is raised:</p>
</pre></div>
</div>
<p>You can use the <code class="docutils literal"><span class="pre">with</span></code> statement for additional convenience:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">with</span> <span class="n">Timeout</span><span class="p">(</span><span class="n">seconds</span><span class="p">,</span> <span class="n">exception</span><span class="p">)</span> <span class="k">as</span> <span class="n">timeout</span><span class="p">:</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">Timeout</span><span class="p">(</span><span class="n">seconds</span><span class="p">,</span> <span class="n">exception</span><span class="p">)</span> <span class="k">as</span> <span class="n">timeout</span><span class="p">:</span>
<span class="k">pass</span> <span class="c1"># ... code block ...</span>
</pre></div>
</div>
@@ -85,10 +86,10 @@ itself is raised:</p>
<p>There is an additional feature when using the <code class="docutils literal"><span class="pre">with</span></code> statement: if
<em>exception</em> is <code class="docutils literal"><span class="pre">False</span></code>, the timeout is still raised, but the with
statement suppresses it, so the code outside the with-block won&#8217;t see it:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">data</span> <span class="o">=</span> <span class="bp">None</span>
<span class="k">with</span> <span class="n">Timeout</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="bp">False</span><span class="p">):</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">data</span> <span class="o">=</span> <span class="kc">None</span>
<span class="k">with</span> <span class="n">Timeout</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="kc">False</span><span class="p">):</span>
<span class="n">data</span> <span class="o">=</span> <span class="n">mysock</span><span class="o">.</span><span class="n">makefile</span><span class="p">()</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span>
<span class="k">if</span> <span class="n">data</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
<span class="k">if</span> <span class="n">data</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="o">...</span> <span class="c1"># 5 seconds passed without reading a line</span>
<span class="k">else</span><span class="p">:</span>
<span class="o">...</span> <span class="c1"># a line was read within 5 seconds</span>
@@ -104,7 +105,7 @@ and is only useful if you&#8217;re planning to raise it directly.</p>
<p>When catching timeouts, keep in mind that the one you catch may not be the
one you set; if you plan on silencing a timeout, always check that it&#8217;s the
same instance that you set:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">timeout</span> <span class="o">=</span> <span class="n">Timeout</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">timeout</span> <span class="o">=</span> <span class="n">Timeout</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="k">try</span><span class="p">:</span>
<span class="o">...</span>
<span class="k">except</span> <span class="n">Timeout</span> <span class="k">as</span> <span class="n">t</span><span class="p">:</span>
@@ -141,7 +142,7 @@ value.</p>
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>seconds</strong> (<em>int or float</em>) &#8211; seconds before timeout occurs</li>
<li><strong>seconds</strong> (<a class="reference external" href="https://docs.python.org/2/library/functions.html#int" title="(in Python v2.7)"><em>int</em></a><em> or </em><a class="reference external" href="https://docs.python.org/2/library/functions.html#float" title="(in Python v2.7)"><em>float</em></a>) &#8211; seconds before timeout occurs</li>
<li><strong>func</strong> &#8211; the callable to execute with a timeout; it must cooperatively yield, or else the timeout will not be able to trigger</li>
<li><strong>*args</strong> &#8211; positional arguments to pass to <em>func</em></li>
<li><strong>**kwds</strong> &#8211; keyword arguments to pass to <em>func</em></li>
@@ -154,7 +155,7 @@ value.</p>
<em>timeout_value</em> if provided, else raises <code class="xref py py-class docutils literal"><span class="pre">Timeout</span></code>.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Raises:</th><td class="field-body"><p class="first"><strong>Timeout</strong> &#8211; if <em>func</em> times out and no <code class="docutils literal"><span class="pre">timeout_value</span></code> has
<tr class="field-odd field"><th class="field-name">Raises:</th><td class="field-body"><p class="first"><a class="reference internal" href="../basic_usage.html#eventlet.Timeout" title="eventlet.Timeout"><strong>Timeout</strong></a> &#8211; if <em>func</em> times out and no <code class="docutils literal"><span class="pre">timeout_value</span></code> has
been provided.</p>
</td>
</tr>
@@ -164,7 +165,7 @@ been provided.</p>
</tbody>
</table>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">data</span> <span class="o">=</span> <span class="n">with_timeout</span><span class="p">(</span><span class="mi">30</span><span class="p">,</span> <span class="n">urllib2</span><span class="o">.</span><span class="n">open</span><span class="p">,</span> <span class="s1">&#39;http://www.google.com/&#39;</span><span class="p">,</span> <span class="n">timeout_value</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">)</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">data</span> <span class="o">=</span> <span class="n">with_timeout</span><span class="p">(</span><span class="mi">30</span><span class="p">,</span> <span class="n">urllib2</span><span class="o">.</span><span class="n">open</span><span class="p">,</span> <span class="s1">&#39;http://www.google.com/&#39;</span><span class="p">,</span> <span class="n">timeout_value</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">)</span>
</pre></div>
</div>
<p>Here <em>data</em> is either the result of the <code class="docutils literal"><span class="pre">get()</span></code> call, or the empty string
@@ -189,21 +190,18 @@ is passed through to the caller.</p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/modules/timeout.txt"
<li><a href="../_sources/modules/timeout.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">
<input type="text" name="q" />
<input type="submit" value="Go" />
<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>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
@@ -225,14 +223,14 @@ is passed through to the caller.</p>
<li class="right" >
<a href="semaphore.html" title="semaphore Semaphore classes"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" >Module Reference</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" >Module Reference</a> &#187;</li>
</ul>
</div>
<div class="footer" role="contentinfo">
&copy; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.5.
&#169; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

View File

@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>websocket Websocket Server &mdash; Eventlet 0.20.0 documentation</title>
<title>websocket Websocket Server &#8212; 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" />
@@ -17,14 +17,15 @@
VERSION: '0.20.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
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="top" title="Eventlet 0.20.0 documentation" href="../index.html" />
<link rel="up" title="Module Reference" href="../modules.html" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="next" title="wsgi WSGI server" href="wsgi.html" />
<link rel="prev" title="timeout Universal Timeouts" href="timeout.html" />
</head>
@@ -44,8 +45,8 @@
<li class="right" >
<a href="timeout.html" title="timeout Universal Timeouts"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" accesskey="U">Module Reference</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" accesskey="U">Module Reference</a> &#187;</li>
</ul>
</div>
@@ -61,10 +62,10 @@ tweaks in the <a class="reference internal" href="wsgi.html#module-eventlet.wsgi
coexist with other WSGI applications.</p>
<p>To create a websocket server, simply decorate a handler method with
<code class="xref py py-class docutils literal"><span class="pre">WebSocketWSGI</span></code> and use it as a wsgi application:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">eventlet</span> <span class="kn">import</span> <span class="n">wsgi</span><span class="p">,</span> <span class="n">websocket</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">eventlet</span> <span class="k">import</span> <span class="n">wsgi</span><span class="p">,</span> <span class="n">websocket</span>
<span class="kn">import</span> <span class="nn">eventlet</span>
<span class="nd">@websocket.WebSocketWSGI</span>
<span class="nd">@websocket</span><span class="o">.</span><span class="n">WebSocketWSGI</span>
<span class="k">def</span> <span class="nf">hello_world</span><span class="p">(</span><span class="n">ws</span><span class="p">):</span>
<span class="n">ws</span><span class="o">.</span><span class="n">send</span><span class="p">(</span><span class="s2">&quot;hello world&quot;</span><span class="p">)</span>
@@ -78,7 +79,7 @@ documentation</p>
</div>
<p>You can find a slightly more elaborate version of this code in the file
<code class="docutils literal"><span class="pre">examples/websocket.py</span></code>.</p>
<p>As of version 0.9.13, eventlet.websocket supports SSL websockets; all that&#8217;s necessary is to use an <a class="reference internal" href="wsgi.html#wsgi-ssl"><span>SSL wsgi server</span></a>.</p>
<p>As of version 0.9.13, eventlet.websocket supports SSL websockets; all that&#8217;s necessary is to use an <a class="reference internal" href="wsgi.html#wsgi-ssl"><span class="std std-ref">SSL wsgi server</span></a>.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">The web socket spec is still under development, and it will be necessary to change the way that this module works in response to spec changes.</p>
@@ -88,7 +89,7 @@ documentation</p>
<em class="property">class </em><code class="descclassname">eventlet.websocket.</code><code class="descname">WebSocketWSGI</code><span class="sig-paren">(</span><em>handler</em><span class="sig-paren">)</span><a class="headerlink" href="#eventlet.websocket.WebSocketWSGI" title="Permalink to this definition"></a></dt>
<dd><p>Wraps a websocket handler function in a WSGI application.</p>
<p>Use it like this:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="nd">@websocket.WebSocketWSGI</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="nd">@websocket</span><span class="o">.</span><span class="n">WebSocketWSGI</span>
<span class="k">def</span> <span class="nf">my_handler</span><span class="p">(</span><span class="n">ws</span><span class="p">):</span>
<span class="n">from_browser</span> <span class="o">=</span> <span class="n">ws</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>
<span class="n">ws</span><span class="o">.</span><span class="n">send</span><span class="p">(</span><span class="s2">&quot;from server&quot;</span><span class="p">)</span>
@@ -165,21 +166,18 @@ websocket message.</p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/modules/websocket.txt"
<li><a href="../_sources/modules/websocket.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">
<input type="text" name="q" />
<input type="submit" value="Go" />
<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>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
@@ -201,14 +199,14 @@ websocket message.</p>
<li class="right" >
<a href="timeout.html" title="timeout Universal Timeouts"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" >Module Reference</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" >Module Reference</a> &#187;</li>
</ul>
</div>
<div class="footer" role="contentinfo">
&copy; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.5.
&#169; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

View File

@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>wsgi WSGI server &mdash; Eventlet 0.20.0 documentation</title>
<title>wsgi WSGI server &#8212; 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" />
@@ -17,14 +17,15 @@
VERSION: '0.20.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
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="top" title="Eventlet 0.20.0 documentation" href="../index.html" />
<link rel="up" title="Module Reference" href="../modules.html" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="next" title="eventlet.green.zmq ØMQ support" href="zmq.html" />
<link rel="prev" title="websocket Websocket Server" href="websocket.html" />
</head>
@@ -44,8 +45,8 @@
<li class="right" >
<a href="websocket.html" title="websocket Websocket Server"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" accesskey="U">Module Reference</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" accesskey="U">Module Reference</a> &#187;</li>
</ul>
</div>
@@ -61,7 +62,7 @@
web server in an application, or as the basis for a more full-featured web
server package. One such package is <a class="reference external" href="http://pypi.python.org/pypi/Spawning/">Spawning</a>.</p>
<p>To launch a wsgi server, simply create a socket and call <a class="reference internal" href="#eventlet.wsgi.server" title="eventlet.wsgi.server"><code class="xref py py-func docutils literal"><span class="pre">eventlet.wsgi.server()</span></code></a> with it:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">eventlet</span> <span class="kn">import</span> <span class="n">wsgi</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">eventlet</span> <span class="k">import</span> <span class="n">wsgi</span>
<span class="kn">import</span> <span class="nn">eventlet</span>
<span class="k">def</span> <span class="nf">hello_world</span><span class="p">(</span><span class="n">env</span><span class="p">,</span> <span class="n">start_response</span><span class="p">):</span>
@@ -149,10 +150,10 @@ Default is True.</li>
<div class="section" id="ssl">
<span id="wsgi-ssl"></span><h2>SSL<a class="headerlink" href="#ssl" title="Permalink to this headline"></a></h2>
<p>Creating a secure server is only slightly more involved than the base example. All that&#8217;s needed is to pass an SSL-wrapped socket to the <a class="reference internal" href="#eventlet.wsgi.server" title="eventlet.wsgi.server"><code class="xref py py-func docutils literal"><span class="pre">server()</span></code></a> method:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">wsgi</span><span class="o">.</span><span class="n">server</span><span class="p">(</span><span class="n">eventlet</span><span class="o">.</span><span class="n">wrap_ssl</span><span class="p">(</span><span class="n">eventlet</span><span class="o">.</span><span class="n">listen</span><span class="p">((</span><span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="mi">8090</span><span class="p">)),</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">wsgi</span><span class="o">.</span><span class="n">server</span><span class="p">(</span><span class="n">eventlet</span><span class="o">.</span><span class="n">wrap_ssl</span><span class="p">(</span><span class="n">eventlet</span><span class="o">.</span><span class="n">listen</span><span class="p">((</span><span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="mi">8090</span><span class="p">)),</span>
<span class="n">certfile</span><span class="o">=</span><span class="s1">&#39;cert.crt&#39;</span><span class="p">,</span>
<span class="n">keyfile</span><span class="o">=</span><span class="s1">&#39;private.key&#39;</span><span class="p">,</span>
<span class="n">server_side</span><span class="o">=</span><span class="bp">True</span><span class="p">),</span>
<span class="n">server_side</span><span class="o">=</span><span class="kc">True</span><span class="p">),</span>
<span class="n">hello_world</span><span class="p">)</span>
</pre></div>
</div>
@@ -167,11 +168,11 @@ is a tuple of <code class="samp docutils literal"><span class="pre">(func,</span
the WSGI environment dictionary, followed by the <cite>args</cite> and then the <cite>kwargs</cite>
in the post hook.</p>
<p>For example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">eventlet</span> <span class="kn">import</span> <span class="n">wsgi</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">eventlet</span> <span class="k">import</span> <span class="n">wsgi</span>
<span class="kn">import</span> <span class="nn">eventlet</span>
<span class="k">def</span> <span class="nf">hook</span><span class="p">(</span><span class="n">env</span><span class="p">,</span> <span class="n">arg1</span><span class="p">,</span> <span class="n">arg2</span><span class="p">,</span> <span class="n">kwarg3</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">kwarg4</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
<span class="k">print</span><span class="p">(</span><span class="s1">&#39;Hook called: </span><span class="si">%s</span><span class="s1"> </span><span class="si">%s</span><span class="s1"> </span><span class="si">%s</span><span class="s1"> </span><span class="si">%s</span><span class="s1"> </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">env</span><span class="p">,</span> <span class="n">arg1</span><span class="p">,</span> <span class="n">arg2</span><span class="p">,</span> <span class="n">kwarg3</span><span class="p">,</span> <span class="n">kwarg4</span><span class="p">))</span>
<span class="k">def</span> <span class="nf">hook</span><span class="p">(</span><span class="n">env</span><span class="p">,</span> <span class="n">arg1</span><span class="p">,</span> <span class="n">arg2</span><span class="p">,</span> <span class="n">kwarg3</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">kwarg4</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Hook called: </span><span class="si">%s</span><span class="s1"> </span><span class="si">%s</span><span class="s1"> </span><span class="si">%s</span><span class="s1"> </span><span class="si">%s</span><span class="s1"> </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">env</span><span class="p">,</span> <span class="n">arg1</span><span class="p">,</span> <span class="n">arg2</span><span class="p">,</span> <span class="n">kwarg3</span><span class="p">,</span> <span class="n">kwarg4</span><span class="p">))</span>
<span class="k">def</span> <span class="nf">hello_world</span><span class="p">(</span><span class="n">env</span><span class="p">,</span> <span class="n">start_response</span><span class="p">):</span>
<span class="n">env</span><span class="p">[</span><span class="s1">&#39;eventlet.posthooks&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
@@ -205,7 +206,7 @@ expect/continue mechanism (PEP333).</p>
<p>To define the &#8220;100 Continue&#8221; response headers, one may call
<code class="xref py py-func docutils literal"><span class="pre">set_hundred_continue_response_header()</span></code> on <code class="samp docutils literal"><span class="pre">env['wsgi.input']</span></code>
as shown in the following example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">eventlet</span> <span class="kn">import</span> <span class="n">wsgi</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">eventlet</span> <span class="k">import</span> <span class="n">wsgi</span>
<span class="kn">import</span> <span class="nn">eventlet</span>
<span class="k">def</span> <span class="nf">wsgi_app</span><span class="p">(</span><span class="n">env</span><span class="p">,</span> <span class="n">start_response</span><span class="p">):</span>
@@ -263,21 +264,18 @@ in the wsgi test case <code class="docutils literal"><span class="pre">tests/wsg
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/modules/wsgi.txt"
<li><a href="../_sources/modules/wsgi.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">
<input type="text" name="q" />
<input type="submit" value="Go" />
<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>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
@@ -299,14 +297,14 @@ in the wsgi test case <code class="docutils literal"><span class="pre">tests/wsg
<li class="right" >
<a href="websocket.html" title="websocket Websocket Server"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" >Module Reference</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="../index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../modules.html" >Module Reference</a> &#187;</li>
</ul>
</div>
<div class="footer" role="contentinfo">
&copy; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.5.
&#169; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Greening The World &mdash; Eventlet 0.20.0 documentation</title>
<title>Greening The World &#8212; 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" />
@@ -17,13 +17,15 @@
VERSION: '0.20.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
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="top" title="Eventlet 0.20.0 documentation" href="index.html" />
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Examples" href="examples.html" />
<link rel="prev" title="Design Patterns" href="design_patterns.html" />
</head>
@@ -43,7 +45,7 @@
<li class="right" >
<a href="design_patterns.html" title="Design Patterns"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
</ul>
</div>
@@ -59,9 +61,9 @@
<div class="section" id="import-green">
<span id="id1"></span><h2>Import Green<a class="headerlink" href="#import-green" title="Permalink to this headline"></a></h2>
<p>The first way of greening an application is to import networking-related libraries from the <code class="docutils literal"><span class="pre">eventlet.green</span></code> package. It contains libraries that have the same interfaces as common standard ones, but they are modified to behave well with green threads. Using this method is a good engineering practice, because the true dependencies are apparent in every file:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">eventlet.green</span> <span class="kn">import</span> <span class="n">socket</span>
<span class="kn">from</span> <span class="nn">eventlet.green</span> <span class="kn">import</span> <span class="n">threading</span>
<span class="kn">from</span> <span class="nn">eventlet.green</span> <span class="kn">import</span> <span class="n">asyncore</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">eventlet.green</span> <span class="k">import</span> <span class="n">socket</span>
<span class="kn">from</span> <span class="nn">eventlet.green</span> <span class="k">import</span> <span class="n">threading</span>
<span class="kn">from</span> <span class="nn">eventlet.green</span> <span class="k">import</span> <span class="n">asyncore</span>
</pre></div>
</div>
<p>This works best if every library can be imported green in this manner. If <code class="docutils literal"><span class="pre">eventlet.green</span></code> lacks a module (for example, non-python-standard modules), then <a class="reference internal" href="#eventlet.patcher.import_patched" title="eventlet.patcher.import_patched"><code class="xref py py-func docutils literal"><span class="pre">import_patched()</span></code></a> function can come to the rescue. It is a replacement for the builtin import statement that greens any module on import.</p>
@@ -69,14 +71,14 @@
<dt id="eventlet.patcher.import_patched">
<code class="descclassname">eventlet.patcher.</code><code class="descname">import_patched</code><span class="sig-paren">(</span><em>module_name</em>, <em>*additional_modules</em>, <em>**kw_additional_modules</em><span class="sig-paren">)</span><a class="headerlink" href="#eventlet.patcher.import_patched" title="Permalink to this definition"></a></dt>
<dd><p>Imports a module in a greened manner, so that the module&#8217;s use of networking libraries like socket will use Eventlet&#8217;s green versions instead. The only required argument is the name of the module to be imported:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">eventlet</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">eventlet</span>
<span class="n">httplib2</span> <span class="o">=</span> <span class="n">eventlet</span><span class="o">.</span><span class="n">import_patched</span><span class="p">(</span><span class="s1">&#39;httplib2&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>Under the hood, it works by temporarily swapping out the &#8220;normal&#8221; versions of the libraries in sys.modules for an eventlet.green equivalent. When the import of the to-be-patched module completes, the state of sys.modules is restored. Therefore, if the patched module contains the statement &#8216;import socket&#8217;, import_patched will have it reference eventlet.green.socket. One weakness of this approach is that it doesn&#8217;t work for late binding (i.e. imports that happen during runtime). Late binding of imports is fortunately rarely done (it&#8217;s slow and against <a class="reference external" href="http://www.python.org/dev/peps/pep-0008/">PEP-8</a>), so in most cases import_patched will work just fine.</p>
<p>One other aspect of import_patched is the ability to specify exactly which modules are patched. Doing so may provide a slight performance benefit since only the needed modules are imported, whereas import_patched with no arguments imports a bunch of modules in case they&#8217;re needed. The <em>additional_modules</em> and <em>kw_additional_modules</em> arguments are both sequences of name/module pairs. Either or both can be used:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">eventlet.green</span> <span class="kn">import</span> <span class="n">socket</span>
<span class="kn">from</span> <span class="nn">eventlet.green</span> <span class="kn">import</span> <span class="n">SocketServer</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">eventlet.green</span> <span class="k">import</span> <span class="n">socket</span>
<span class="kn">from</span> <span class="nn">eventlet.green</span> <span class="k">import</span> <span class="n">SocketServer</span>
<span class="n">BaseHTTPServer</span> <span class="o">=</span> <span class="n">eventlet</span><span class="o">.</span><span class="n">import_patched</span><span class="p">(</span><span class="s1">&#39;BaseHTTPServer&#39;</span><span class="p">,</span>
<span class="p">(</span><span class="s1">&#39;socket&#39;</span><span class="p">,</span> <span class="n">socket</span><span class="p">),</span>
<span class="p">(</span><span class="s1">&#39;SocketServer&#39;</span><span class="p">,</span> <span class="n">SocketServer</span><span class="p">))</span>
@@ -95,14 +97,14 @@ library. This has the disadvantage of appearing quite magical, but the advantag
<dt id="eventlet.patcher.monkey_patch">
<code class="descclassname">eventlet.patcher.</code><code class="descname">monkey_patch</code><span class="sig-paren">(</span><em>os=None</em>, <em>select=None</em>, <em>socket=None</em>, <em>thread=None</em>, <em>time=None</em>, <em>psycopg=None</em><span class="sig-paren">)</span><a class="headerlink" href="#eventlet.patcher.monkey_patch" title="Permalink to this definition"></a></dt>
<dd><p>This function monkeypatches the key system modules by replacing their key elements with green equivalents. If no arguments are specified, everything is patched:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">eventlet</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">eventlet</span>
<span class="n">eventlet</span><span class="o">.</span><span class="n">monkey_patch</span><span class="p">()</span>
</pre></div>
</div>
<p>The keyword arguments afford some control over which modules are patched, in case that&#8217;s important. Most patch the single module of the same name (e.g. time=True means that the time module is patched [time.sleep is patched by eventlet.sleep]). The exceptions to this rule are <em>socket</em>, which also patches the <a class="reference external" href="http://docs.python.org/library/ssl.html#module-ssl" title="(in Python v2.7)"><code class="xref py py-mod docutils literal"><span class="pre">ssl</span></code></a> module if present; and <em>thread</em>, which patches <a class="reference external" href="http://docs.python.org/library/thread.html#module-thread" title="(in Python v2.7)"><code class="xref py py-mod docutils literal"><span class="pre">thread</span></code></a>, <a class="reference external" href="http://docs.python.org/library/threading.html#module-threading" title="(in Python v2.7)"><code class="xref py py-mod docutils literal"><span class="pre">threading</span></code></a>, and <a class="reference external" href="http://docs.python.org/library/queue.html#module-Queue" title="(in Python v2.7)"><code class="xref py py-mod docutils literal"><span class="pre">Queue</span></code></a>.</p>
<p>The keyword arguments afford some control over which modules are patched, in case that&#8217;s important. Most patch the single module of the same name (e.g. time=True means that the time module is patched [time.sleep is patched by eventlet.sleep]). The exceptions to this rule are <em>socket</em>, which also patches the <a class="reference external" href="https://docs.python.org/2/library/ssl.html#module-ssl" title="(in Python v2.7)"><code class="xref py py-mod docutils literal"><span class="pre">ssl</span></code></a> module if present; and <em>thread</em>, which patches <a class="reference external" href="https://docs.python.org/2/library/thread.html#module-thread" title="(in Python v2.7)"><code class="xref py py-mod docutils literal"><span class="pre">thread</span></code></a>, <a class="reference external" href="https://docs.python.org/2/library/threading.html#module-threading" title="(in Python v2.7)"><code class="xref py py-mod docutils literal"><span class="pre">threading</span></code></a>, and <a class="reference external" href="https://docs.python.org/2/library/queue.html#module-Queue" title="(in Python v2.7)"><code class="xref py py-mod docutils literal"><span class="pre">Queue</span></code></a>.</p>
<p>Here&#8217;s an example of using monkey_patch to patch only a few modules:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">eventlet</span>
<span class="n">eventlet</span><span class="o">.</span><span class="n">monkey_patch</span><span class="p">(</span><span class="n">socket</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">select</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">eventlet</span>
<span class="n">eventlet</span><span class="o">.</span><span class="n">monkey_patch</span><span class="p">(</span><span class="n">socket</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">select</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</pre></div>
</div>
<p>It is important to call <a class="reference internal" href="#eventlet.patcher.monkey_patch" title="eventlet.patcher.monkey_patch"><code class="xref py py-func docutils literal"><span class="pre">monkey_patch()</span></code></a> as early in the lifetime of the application as possible. Try to do it as one of the first lines in the main module. The reason for this is that sometimes there is a class that inherits from a class that needs to be greened &#8211; e.g. a class that inherits from socket.socket &#8211; and inheritance is done at import time, so therefore the monkeypatching should happen before the derived class is defined. It&#8217;s safe to call monkey_patch multiple times.</p>
@@ -144,21 +146,18 @@ library. This has the disadvantage of appearing quite magical, but the advantag
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/patching.txt"
<li><a href="_sources/patching.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">
<input type="text" name="q" />
<input type="submit" value="Go" />
<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>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
@@ -180,13 +179,13 @@ library. This has the disadvantage of appearing quite magical, but the advantag
<li class="right" >
<a href="design_patterns.html" title="Design Patterns"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
</ul>
</div>
<div class="footer" role="contentinfo">
&copy; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.5.
&#169; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

View File

@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Python Module Index &mdash; Eventlet 0.20.0 documentation</title>
<title>Python Module Index &#8212; 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" />
@@ -17,13 +17,15 @@
VERSION: '0.20.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
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="top" title="Eventlet 0.20.0 documentation" href="index.html" />
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
@@ -38,7 +40,7 @@
<li class="right" >
<a href="#" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
</ul>
</div>
@@ -55,8 +57,8 @@
<a href="#cap-z"><strong>z</strong></a>
</div>
<table class="indextable modindextable" cellspacing="0" cellpadding="2">
<tr class="pcap"><td></td><td>&nbsp;</td><td></td></tr>
<table class="indextable modindextable">
<tr class="pcap"><td></td><td>&#160;</td><td></td></tr>
<tr class="cap" id="cap-e"><td></td><td>
<strong>e</strong></td><td></td></tr>
<tr>
@@ -67,75 +69,75 @@
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&nbsp;&nbsp;&nbsp;
<td>&#160;&#160;&#160;
<a href="modules/backdoor.html#module-eventlet.backdoor"><code class="xref">eventlet.backdoor</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&nbsp;&nbsp;&nbsp;
<td>&#160;&#160;&#160;
<a href="modules/corolocal.html#module-eventlet.corolocal"><code class="xref">eventlet.corolocal</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&nbsp;&nbsp;&nbsp;
<td>&#160;&#160;&#160;
<a href="modules/dagpool.html#module-eventlet.dagpool"><code class="xref">eventlet.dagpool</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&nbsp;&nbsp;&nbsp;
<td>&#160;&#160;&#160;
<a href="modules/db_pool.html#module-eventlet.db_pool"><code class="xref">eventlet.db_pool</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&nbsp;&nbsp;&nbsp;
<td>&#160;&#160;&#160;
<a href="modules/debug.html#module-eventlet.debug"><code class="xref">eventlet.debug</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&nbsp;&nbsp;&nbsp;
<td>&#160;&#160;&#160;
<a href="modules/event.html#module-eventlet.event"><code class="xref">eventlet.event</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&nbsp;&nbsp;&nbsp;
<td>&#160;&#160;&#160;
<a href="modules/zmq.html#module-eventlet.green.zmq"><code class="xref">eventlet.green.zmq</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&nbsp;&nbsp;&nbsp;
<td>&#160;&#160;&#160;
<a href="modules/greenpool.html#module-eventlet.greenpool"><code class="xref">eventlet.greenpool</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&nbsp;&nbsp;&nbsp;
<td>&#160;&#160;&#160;
<a href="modules/greenthread.html#module-eventlet.greenthread"><code class="xref">eventlet.greenthread</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&nbsp;&nbsp;&nbsp;
<td>&#160;&#160;&#160;
<a href="modules/pools.html#module-eventlet.pools"><code class="xref">eventlet.pools</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&nbsp;&nbsp;&nbsp;
<td>&#160;&#160;&#160;
<a href="modules/queue.html#module-eventlet.queue"><code class="xref">eventlet.queue</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&nbsp;&nbsp;&nbsp;
<td>&#160;&#160;&#160;
<a href="threading.html#module-eventlet.tpool"><code class="xref">eventlet.tpool</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&nbsp;&nbsp;&nbsp;
<td>&#160;&#160;&#160;
<a href="modules/websocket.html#module-eventlet.websocket"><code class="xref">eventlet.websocket</code></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&nbsp;&nbsp;&nbsp;
<td>&#160;&#160;&#160;
<a href="modules/wsgi.html#module-eventlet.wsgi"><code class="xref">eventlet.wsgi</code></a></td><td>
<em></em></td></tr>
<tr class="pcap"><td></td><td>&nbsp;</td><td></td></tr>
<tr class="pcap"><td></td><td>&#160;</td><td></td></tr>
<tr class="cap" id="cap-z"><td></td><td>
<strong>z</strong></td><td></td></tr>
<tr>
@@ -154,14 +156,11 @@
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<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>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
@@ -177,13 +176,13 @@
<li class="right" >
<a href="#" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
</ul>
</div>
<div class="footer" role="contentinfo">
&copy; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.5.
&#169; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

View File

@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Search &mdash; Eventlet 0.20.0 documentation</title>
<title>Search &#8212; 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" />
@@ -17,14 +17,16 @@
VERSION: '0.20.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
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/searchtools.js"></script>
<link rel="top" title="Eventlet 0.20.0 documentation" href="index.html" />
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="#" />
<script type="text/javascript">
jQuery(function() { Search.loadIndex("searchindex.js"); });
</script>
@@ -43,7 +45,7 @@
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
</ul>
</div>
@@ -94,13 +96,13 @@
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
</ul>
</div>
<div class="footer" role="contentinfo">
&copy; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.5.
&#169; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

File diff suppressed because one or more lines are too long

View File

@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Using SSL With Eventlet &mdash; Eventlet 0.20.0 documentation</title>
<title>Using SSL With Eventlet &#8212; 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" />
@@ -17,13 +17,15 @@
VERSION: '0.20.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
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="top" title="Eventlet 0.20.0 documentation" href="index.html" />
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Threads" href="threading.html" />
<link rel="prev" title="Examples" href="examples.html" />
</head>
@@ -43,7 +45,7 @@
<li class="right" >
<a href="examples.html" title="Examples"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
</ul>
</div>
@@ -56,49 +58,49 @@
<h1>Using SSL With Eventlet<a class="headerlink" href="#using-ssl-with-eventlet" title="Permalink to this headline"></a></h1>
<p>Eventlet makes it easy to use non-blocking SSL sockets. If you&#8217;re using Python 2.6 or later, you&#8217;re all set, eventlet wraps the built-in ssl module. If on Python 2.5 or 2.4, you have to install <a class="reference external" href="https://launchpad.net/pyopenssl">pyOpenSSL</a> to use eventlet.</p>
<p>In either case, the <code class="docutils literal"><span class="pre">green</span></code> modules handle SSL sockets transparently, just like their standard counterparts. As an example, <code class="xref py py-mod docutils literal"><span class="pre">eventlet.green.urllib2</span></code> can be used to fetch https urls in as non-blocking a fashion as you please:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">eventlet.green</span> <span class="kn">import</span> <span class="n">urllib2</span>
<span class="kn">from</span> <span class="nn">eventlet</span> <span class="kn">import</span> <span class="n">spawn</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">eventlet.green</span> <span class="k">import</span> <span class="n">urllib2</span>
<span class="kn">from</span> <span class="nn">eventlet</span> <span class="k">import</span> <span class="n">spawn</span>
<span class="n">bodies</span> <span class="o">=</span> <span class="p">[</span><span class="n">spawn</span><span class="p">(</span><span class="n">urllib2</span><span class="o">.</span><span class="n">urlopen</span><span class="p">,</span> <span class="n">url</span><span class="p">)</span>
<span class="k">for</span> <span class="n">url</span> <span class="ow">in</span> <span class="p">(</span><span class="s2">&quot;https://secondlife.com&quot;</span><span class="p">,</span><span class="s2">&quot;https://google.com&quot;</span><span class="p">)]</span>
<span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="n">bodies</span><span class="p">:</span>
<span class="k">print</span><span class="p">(</span><span class="n">b</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span><span class="o">.</span><span class="n">read</span><span class="p">())</span>
<span class="nb">print</span><span class="p">(</span><span class="n">b</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span><span class="o">.</span><span class="n">read</span><span class="p">())</span>
</pre></div>
</div>
<div class="section" id="with-python-2-6">
<h2>With Python 2.6<a class="headerlink" href="#with-python-2-6" title="Permalink to this headline"></a></h2>
<p>To use ssl sockets directly in Python 2.6, use <code class="xref py py-mod docutils literal"><span class="pre">eventlet.green.ssl</span></code>, which is a non-blocking wrapper around the standard Python <a class="reference external" href="http://docs.python.org/library/ssl.html#module-ssl" title="(in Python v2.7)"><code class="xref py py-mod docutils literal"><span class="pre">ssl</span></code></a> module, and which has the same interface. See the standard documentation for instructions on use.</p>
<p>To use ssl sockets directly in Python 2.6, use <code class="xref py py-mod docutils literal"><span class="pre">eventlet.green.ssl</span></code>, which is a non-blocking wrapper around the standard Python <a class="reference external" href="https://docs.python.org/2/library/ssl.html#module-ssl" title="(in Python v2.7)"><code class="xref py py-mod docutils literal"><span class="pre">ssl</span></code></a> module, and which has the same interface. See the standard documentation for instructions on use.</p>
</div>
<div class="section" id="with-python-2-5-or-earlier">
<h2>With Python 2.5 or Earlier<a class="headerlink" href="#with-python-2-5-or-earlier" title="Permalink to this headline"></a></h2>
<p>Prior to Python 2.6, there is no <a class="reference external" href="http://docs.python.org/library/ssl.html#module-ssl" title="(in Python v2.7)"><code class="xref py py-mod docutils literal"><span class="pre">ssl</span></code></a>, so SSL support is much weaker. Eventlet relies on pyOpenSSL to implement its SSL support on these older versions, so be sure to install pyOpenSSL, or you&#8217;ll get an ImportError whenever your system tries to make an SSL connection.</p>
<p>Prior to Python 2.6, there is no <a class="reference external" href="https://docs.python.org/2/library/ssl.html#module-ssl" title="(in Python v2.7)"><code class="xref py py-mod docutils literal"><span class="pre">ssl</span></code></a>, so SSL support is much weaker. Eventlet relies on pyOpenSSL to implement its SSL support on these older versions, so be sure to install pyOpenSSL, or you&#8217;ll get an ImportError whenever your system tries to make an SSL connection.</p>
<p>Once pyOpenSSL is installed, you can then use the <code class="docutils literal"><span class="pre">eventlet.green</span></code> modules, like <code class="xref py py-mod docutils literal"><span class="pre">eventlet.green.httplib</span></code> to fetch https urls. You can also use <code class="xref py py-func docutils literal"><span class="pre">eventlet.green.socket.ssl()</span></code>, which is a nonblocking wrapper for <code class="xref py py-func docutils literal"><span class="pre">socket.ssl()</span></code>.</p>
</div>
<div class="section" id="pyopenssl">
<h2>PyOpenSSL<a class="headerlink" href="#pyopenssl" title="Permalink to this headline"></a></h2>
<p><code class="xref py py-mod docutils literal"><span class="pre">eventlet.green.OpenSSL</span></code> has exactly the same interface as <a class="reference external" href="https://launchpad.net/pyopenssl">pyOpenSSL</a> <a class="reference external" href="http://pyopenssl.sourceforge.net/pyOpenSSL.html/">(docs)</a>, and works in all versions of Python. This module is much more powerful than <code class="xref py py-func docutils literal"><span class="pre">socket.ssl()</span></code>, and may have some advantages over <a class="reference external" href="http://docs.python.org/library/ssl.html#module-ssl" title="(in Python v2.7)"><code class="xref py py-mod docutils literal"><span class="pre">ssl</span></code></a>, depending on your needs.</p>
<p><code class="xref py py-mod docutils literal"><span class="pre">eventlet.green.OpenSSL</span></code> has exactly the same interface as <a class="reference external" href="https://launchpad.net/pyopenssl">pyOpenSSL</a> <a class="reference external" href="http://pyopenssl.sourceforge.net/pyOpenSSL.html/">(docs)</a>, and works in all versions of Python. This module is much more powerful than <code class="xref py py-func docutils literal"><span class="pre">socket.ssl()</span></code>, and may have some advantages over <a class="reference external" href="https://docs.python.org/2/library/ssl.html#module-ssl" title="(in Python v2.7)"><code class="xref py py-mod docutils literal"><span class="pre">ssl</span></code></a>, depending on your needs.</p>
<p>Here&#8217;s an example of a server:</p>
<div class="highlight-python"><div class="highlight"><pre>from eventlet.green import socket
from eventlet.green.OpenSSL import SSL
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">eventlet.green</span> <span class="k">import</span> <span class="n">socket</span>
<span class="kn">from</span> <span class="nn">eventlet.green.OpenSSL</span> <span class="k">import</span> <span class="n">SSL</span>
# insecure context, only for example purposes
context = SSL.Context(SSL.SSLv23_METHOD)
context.set_verify(SSL.VERIFY_NONE, lambda *x: True))
<span class="c1"># insecure context, only for example purposes</span>
<span class="n">context</span> <span class="o">=</span> <span class="n">SSL</span><span class="o">.</span><span class="n">Context</span><span class="p">(</span><span class="n">SSL</span><span class="o">.</span><span class="n">SSLv23_METHOD</span><span class="p">)</span>
<span class="n">context</span><span class="o">.</span><span class="n">set_verify</span><span class="p">(</span><span class="n">SSL</span><span class="o">.</span><span class="n">VERIFY_NONE</span><span class="p">,</span> <span class="k">lambda</span> <span class="o">*</span><span class="n">x</span><span class="p">:</span> <span class="kc">True</span><span class="p">))</span>
# create underlying green socket and wrap it in ssl
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connection = SSL.Connection(context, sock)
<span class="c1"># create underlying green socket and wrap it in ssl</span>
<span class="n">sock</span> <span class="o">=</span> <span class="n">socket</span><span class="o">.</span><span class="n">socket</span><span class="p">(</span><span class="n">socket</span><span class="o">.</span><span class="n">AF_INET</span><span class="p">,</span> <span class="n">socket</span><span class="o">.</span><span class="n">SOCK_STREAM</span><span class="p">)</span>
<span class="n">connection</span> <span class="o">=</span> <span class="n">SSL</span><span class="o">.</span><span class="n">Connection</span><span class="p">(</span><span class="n">context</span><span class="p">,</span> <span class="n">sock</span><span class="p">)</span>
# configure as server
connection.set_accept_state()
connection.bind((&#39;127.0.0.1&#39;, 80443))
connection.listen(50)
<span class="c1"># configure as server</span>
<span class="n">connection</span><span class="o">.</span><span class="n">set_accept_state</span><span class="p">()</span>
<span class="n">connection</span><span class="o">.</span><span class="n">bind</span><span class="p">((</span><span class="s1">&#39;127.0.0.1&#39;</span><span class="p">,</span> <span class="mi">80443</span><span class="p">))</span>
<span class="n">connection</span><span class="o">.</span><span class="n">listen</span><span class="p">(</span><span class="mi">50</span><span class="p">)</span>
# accept one client connection then close up shop
client_conn, addr = connection.accept()
print(client_conn.read(100))
client_conn.shutdown()
client_conn.close()
connection.close()
<span class="c1"># accept one client connection then close up shop</span>
<span class="n">client_conn</span><span class="p">,</span> <span class="n">addr</span> <span class="o">=</span> <span class="n">connection</span><span class="o">.</span><span class="n">accept</span><span class="p">()</span>
<span class="nb">print</span><span class="p">(</span><span class="n">client_conn</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="mi">100</span><span class="p">))</span>
<span class="n">client_conn</span><span class="o">.</span><span class="n">shutdown</span><span class="p">()</span>
<span class="n">client_conn</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<span class="n">connection</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
</pre></div>
</div>
</div>
@@ -129,21 +131,18 @@ connection.close()
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/ssl.txt"
<li><a href="_sources/ssl.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">
<input type="text" name="q" />
<input type="submit" value="Go" />
<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>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
@@ -165,13 +164,13 @@ connection.close()
<li class="right" >
<a href="examples.html" title="Examples"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
</ul>
</div>
<div class="footer" role="contentinfo">
&copy; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.5.
&#169; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

View File

@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Testing Eventlet &mdash; Eventlet 0.20.0 documentation</title>
<title>Testing Eventlet &#8212; 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" />
@@ -17,13 +17,15 @@
VERSION: '0.20.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
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="top" title="Eventlet 0.20.0 documentation" href="index.html" />
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Environment Variables" href="environment.html" />
<link rel="prev" title="Understanding Eventlet Hubs" href="hubs.html" />
</head>
@@ -43,7 +45,7 @@
<li class="right" >
<a href="hubs.html" title="Understanding Eventlet Hubs"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
</ul>
</div>
@@ -55,15 +57,15 @@
<div class="section" id="testing-eventlet">
<h1>Testing Eventlet<a class="headerlink" href="#testing-eventlet" title="Permalink to this headline"></a></h1>
<p>Eventlet is tested using <a class="reference external" href="http://somethingaboutorange.com/mrl/projects/nose/">Nose</a>. To run tests, simply install nose, and then, in the eventlet tree, do:</p>
<div class="highlight-sh"><div class="highlight"><pre>$ python setup.py <span class="nb">test</span>
<div class="highlight-sh"><div class="highlight"><pre><span></span>$ python setup.py <span class="nb">test</span>
</pre></div>
</div>
<p>If you want access to all the nose plugins via command line, you can run:</p>
<div class="highlight-sh"><div class="highlight"><pre>$ python setup.py nosetests
<div class="highlight-sh"><div class="highlight"><pre><span></span>$ python setup.py nosetests
</pre></div>
</div>
<p>Lastly, you can just use nose directly if you want:</p>
<div class="highlight-sh"><div class="highlight"><pre>$ nosetests
<div class="highlight-sh"><div class="highlight"><pre><span></span>$ nosetests
</pre></div>
</div>
<p>That&#8217;s it! The output from running nose is the same as unittest&#8217;s output, if the entire directory was one big test file.</p>
@@ -71,7 +73,7 @@
<div class="section" id="doctests">
<h2>Doctests<a class="headerlink" href="#doctests" title="Permalink to this headline"></a></h2>
<p>To run the doctests included in many of the eventlet modules, use this command:</p>
<div class="highlight-sh"><div class="highlight"><pre>$ nosetests --with-doctest eventlet/*.py
<div class="highlight-sh"><div class="highlight"><pre><span></span>$ nosetests --with-doctest eventlet/*.py
</pre></div>
</div>
<p>Currently there are 16 doctests.</p>
@@ -80,7 +82,7 @@
<h2>Standard Library Tests<a class="headerlink" href="#standard-library-tests" title="Permalink to this headline"></a></h2>
<p>Eventlet provides the ability to test itself with the standard Python networking tests. This verifies that the libraries it wraps work at least as well as the standard ones do. The directory tests/stdlib contains a bunch of stubs that import the standard lib tests from your system and run them. If you do not have any tests in your python distribution, they&#8217;ll simply fail to import.</p>
<p>There&#8217;s a convenience module called all.py designed to handle the impedance mismatch between Nose and the standard tests:</p>
<div class="highlight-sh"><div class="highlight"><pre>$ nosetests tests/stdlib/all.py
<div class="highlight-sh"><div class="highlight"><pre><span></span>$ nosetests tests/stdlib/all.py
</pre></div>
</div>
<p>That will run all the tests, though the output will be a little weird because it will look like Nose is running about 20 tests, each of which consists of a bunch of sub-tests. Not all test modules are present in all versions of Python, so there will be an occasional printout of &#8220;Not importing %s, it doesn&#8217;t exist in this installation/version of Python&#8221;.</p>
@@ -89,17 +91,17 @@
<div class="section" id="testing-eventlet-hubs">
<h2>Testing Eventlet Hubs<a class="headerlink" href="#testing-eventlet-hubs" title="Permalink to this headline"></a></h2>
<p>When you run the tests, Eventlet will use the most appropriate hub for the current platform to do its dispatch. It&#8217;s sometimes useful when making changes to Eventlet to test those changes on hubs other than the default. You can do this with the <code class="docutils literal"><span class="pre">EVENTLET_HUB</span></code> environment variable.</p>
<div class="highlight-sh"><div class="highlight"><pre>$ <span class="nv">EVENTLET_HUB</span><span class="o">=</span>epolls nosetests
<div class="highlight-sh"><div class="highlight"><pre><span></span>$ <span class="nv">EVENTLET_HUB</span><span class="o">=</span>epolls nosetests
</pre></div>
</div>
<p>See <a class="reference internal" href="hubs.html#understanding-hubs"><span>Understanding Eventlet Hubs</span></a> for the full list of hubs.</p>
<p>See <a class="reference internal" href="hubs.html#understanding-hubs"><span class="std std-ref">Understanding Eventlet Hubs</span></a> for the full list of hubs.</p>
</div>
<div class="section" id="writing-tests">
<h2>Writing Tests<a class="headerlink" href="#writing-tests" title="Permalink to this headline"></a></h2>
<p>What follows are some notes on writing tests, in no particular order.</p>
<p>The filename convention when writing a test for module <cite>foo</cite> is to name the test <cite>foo_test.py</cite>. We don&#8217;t yet have a convention for tests that are of finer granularity, but a sensible one might be <cite>foo_class_test.py</cite>.</p>
<p>If you are writing a test that involves a client connecting to a spawned server, it is best to not use a hardcoded port because that makes it harder to parallelize tests. Instead bind the server to 0, and then look up its port when connecting the client, like this:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">server_sock</span> <span class="o">=</span> <span class="n">eventlet</span><span class="o">.</span><span class="n">listener</span><span class="p">((</span><span class="s1">&#39;127.0.0.1&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">server_sock</span> <span class="o">=</span> <span class="n">eventlet</span><span class="o">.</span><span class="n">listener</span><span class="p">((</span><span class="s1">&#39;127.0.0.1&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span>
<span class="n">client_sock</span> <span class="o">=</span> <span class="n">eventlet</span><span class="o">.</span><span class="n">connect</span><span class="p">((</span><span class="s1">&#39;localhost&#39;</span><span class="p">,</span> <span class="n">server_sock</span><span class="o">.</span><span class="n">getsockname</span><span class="p">()[</span><span class="mi">1</span><span class="p">]))</span>
</pre></div>
</div>
@@ -107,12 +109,12 @@
<div class="section" id="coverage">
<h2>Coverage<a class="headerlink" href="#coverage" title="Permalink to this headline"></a></h2>
<p>Coverage.py is an awesome tool for evaluating how much code was exercised by unit tests. Nose supports it if both are installed, so it&#8217;s easy to generate coverage reports for eventlet. Here&#8217;s how:</p>
<div class="highlight-sh"><div class="highlight"><pre>nosetests --with-coverage --cover-package<span class="o">=</span>eventlet
<div class="highlight-sh"><div class="highlight"><pre><span></span>nosetests --with-coverage --cover-package<span class="o">=</span>eventlet
</pre></div>
</div>
<p>After running the tests to completion, this will emit a huge wodge of module names and line numbers. For some reason, the <code class="docutils literal"><span class="pre">--cover-inclusive</span></code> option breaks everything rather than serving its purpose of limiting the coverage to the local files, so don&#8217;t use that.</p>
<p>The html option is quite useful because it generates nicely-formatted HTML files that are much easier to read than line-number soup. Here&#8217;s a command that generates the annotation, dumping the html files into a directory called &#8220;cover&#8221;:</p>
<div class="highlight-sh"><div class="highlight"><pre>coverage html -d cover --omit<span class="o">=</span><span class="s1">&#39;tempmod,&lt;console&gt;,tests&#39;</span>
<div class="highlight-sh"><div class="highlight"><pre><span></span>coverage html -d cover --omit<span class="o">=</span><span class="s1">&#39;tempmod,&lt;console&gt;,tests&#39;</span>
</pre></div>
</div>
<p>(<code class="docutils literal"><span class="pre">tempmod</span></code> and <code class="docutils literal"><span class="pre">console</span></code> are omitted because they get thrown away at the completion of their unit tests and coverage.py isn&#8217;t smart enough to detect this.)</p>
@@ -146,21 +148,18 @@
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/testing.txt"
<li><a href="_sources/testing.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">
<input type="text" name="q" />
<input type="submit" value="Go" />
<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>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
@@ -182,13 +181,13 @@
<li class="right" >
<a href="hubs.html" title="Understanding Eventlet Hubs"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
</ul>
</div>
<div class="footer" role="contentinfo">
&copy; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.5.
&#169; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

View File

@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Threads &mdash; Eventlet 0.20.0 documentation</title>
<title>Threads &#8212; 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" />
@@ -17,13 +17,15 @@
VERSION: '0.20.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
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="top" title="Eventlet 0.20.0 documentation" href="index.html" />
<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>
@@ -43,7 +45,7 @@
<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> &raquo;</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
</ul>
</div>
@@ -58,14 +60,14 @@
<img alt="_images/threading_illustration.png" src="_images/threading_illustration.png" />
<p>You can only communicate cross-thread using the &#8220;real&#8221; thread primitives and pipes. Fortunately, there&#8217;s little reason to use threads for concurrency when you&#8217;re already using coroutines.</p>
<p>The vast majority of the times you&#8217;ll want to use threads are to wrap some operation that is not &#8220;green&#8221;, 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>pyevent hub</span></a> is not compatible with threads.</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-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">thread</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">eventlet</span> <span class="kn">import</span> <span class="n">tpool</span>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">thread</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">eventlet</span> <span class="k">import</span> <span class="n">tpool</span>
<span class="gp">&gt;&gt;&gt; </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="k">print</span><span class="p">(</span><span class="s2">&quot;running in new thread:&quot;</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="nb">print</span><span class="p">(</span><span class="s2">&quot;running in new thread:&quot;</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">&gt;&gt;&gt; </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>
@@ -132,21 +134,18 @@ wrapped in Proxy objects when accessed.</p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/threading.txt"
<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">
<input type="text" name="q" />
<input type="submit" value="Go" />
<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>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
@@ -168,13 +167,13 @@ wrapped in Proxy objects when accessed.</p>
<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> &raquo;</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
</ul>
</div>
<div class="footer" role="contentinfo">
&copy; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.5.
&#169; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

View File

@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Zeromq &mdash; Eventlet 0.20.0 documentation</title>
<title>Zeromq &#8212; 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" />
@@ -17,13 +17,15 @@
VERSION: '0.20.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
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="top" title="Eventlet 0.20.0 documentation" href="index.html" />
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Understanding Eventlet Hubs" href="hubs.html" />
<link rel="prev" title="Threads" href="threading.html" />
</head>
@@ -43,7 +45,7 @@
<li class="right" >
<a href="threading.html" title="Threads"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
</ul>
</div>
@@ -102,21 +104,18 @@ while simultaneously accepting incoming connections from multiple endpoints boun
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/zeromq.txt"
<li><a href="_sources/zeromq.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">
<input type="text" name="q" />
<input type="submit" value="Go" />
<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>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
@@ -138,13 +137,13 @@ while simultaneously accepting incoming connections from multiple endpoints boun
<li class="right" >
<a href="threading.html" title="Threads"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &raquo;</li>
<li class="nav-item nav-item-0"><a href="index.html">Eventlet 0.20.0 documentation</a> &#187;</li>
</ul>
</div>
<div class="footer" role="contentinfo">
&copy; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.5.
&#169; Copyright 2005-2010, Eventlet Contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){