/usr/share/doc/python-pymongo-doc/html/examples/gevent.html is in python-pymongo-doc 2.6.3-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Gevent — PyMongo 2.6.3 documentation</title>
<link rel="stylesheet" href="../_static/default.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '2.6.3',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</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/sidebar.js"></script>
<link rel="top" title="PyMongo 2.6.3 documentation" href="../index.html" />
<link rel="up" title="Changelog" href="../changelog.html" />
<link rel="next" title="Requests" href="requests.html" />
<link rel="prev" title="Python 3 FAQ" href="../python3.html" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="requests.html" title="Requests"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="../python3.html" title="Python 3 FAQ"
accesskey="P">previous</a> |</li>
<li><a href="../index.html">PyMongo 2.6.3 documentation</a> »</li>
<li><a href="../changelog.html" accesskey="U">Changelog</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="gevent">
<h1>Gevent<a class="headerlink" href="#gevent" title="Permalink to this headline">¶</a></h1>
<p>PyMongo supports <a class="reference external" href="http://www.gevent.org/">Gevent</a>. Simply call Gevent’s
<tt class="docutils literal"><span class="pre">monkey.patch_all()</span></tt> before loading any other modules:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="c"># You must call patch_all() *before* importing any other modules</span>
<span class="gp">>>> </span><span class="kn">from</span> <span class="nn">gevent</span> <span class="kn">import</span> <span class="n">monkey</span><span class="p">;</span> <span class="n">monkey</span><span class="o">.</span><span class="n">patch_all</span><span class="p">()</span>
<span class="gp">>>> </span><span class="kn">from</span> <span class="nn">pymongo</span> <span class="kn">import</span> <span class="n">MongoClient</span>
<span class="gp">>>> </span><span class="n">client</span> <span class="o">=</span> <span class="n">MongoClient</span><span class="p">()</span>
</pre></div>
</div>
<p>PyMongo’s Gevent support means
that <a class="reference internal" href="../api/pymongo/mongo_client.html#pymongo.mongo_client.MongoClient.start_request" title="pymongo.mongo_client.MongoClient.start_request"><tt class="xref py py-meth docutils literal"><span class="pre">start_request()</span></tt></a> ensures the
current greenlet (not merely the current thread) uses the same socket for all
operations until <a class="reference internal" href="../api/pymongo/mongo_client.html#pymongo.mongo_client.MongoClient.end_request" title="pymongo.mongo_client.MongoClient.end_request"><tt class="xref py py-meth docutils literal"><span class="pre">end_request()</span></tt></a> is called.
See the <a class="reference internal" href="requests.html"><em>requests documentation</em></a> for details on requests in
PyMongo.</p>
<div class="section" id="using-gevent-with-threads">
<h2>Using Gevent With Threads<a class="headerlink" href="#using-gevent-with-threads" title="Permalink to this headline">¶</a></h2>
<p>If you need to use standard Python threads in the same process as Gevent and
greenlets, run <tt class="docutils literal"><span class="pre">monkey.patch_socket()</span></tt>, rather than
<tt class="docutils literal"><span class="pre">monkey.patch_all()</span></tt>, and create a
<a class="reference internal" href="../api/pymongo/mongo_client.html#pymongo.mongo_client.MongoClient" title="pymongo.mongo_client.MongoClient"><tt class="xref py py-class docutils literal"><span class="pre">MongoClient</span></tt></a> with <tt class="docutils literal"><span class="pre">use_greenlets=True</span></tt>.
The <a class="reference internal" href="../api/pymongo/mongo_client.html#pymongo.mongo_client.MongoClient" title="pymongo.mongo_client.MongoClient"><tt class="xref py py-class docutils literal"><span class="pre">MongoClient</span></tt></a> will use a special greenlet-aware
connection pool.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">gevent</span> <span class="kn">import</span> <span class="n">monkey</span><span class="p">;</span> <span class="n">monkey</span><span class="o">.</span><span class="n">patch_socket</span><span class="p">()</span>
<span class="gp">>>> </span><span class="kn">from</span> <span class="nn">pymongo</span> <span class="kn">import</span> <span class="n">MongoClient</span>
<span class="gp">>>> </span><span class="n">client</span> <span class="o">=</span> <span class="n">MongoClient</span><span class="p">(</span><span class="n">use_greenlets</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
</pre></div>
</div>
<p>An instance of <a class="reference internal" href="../api/pymongo/mongo_replica_set_client.html#pymongo.mongo_replica_set_client.MongoReplicaSetClient" title="pymongo.mongo_replica_set_client.MongoReplicaSetClient"><tt class="xref py py-class docutils literal"><span class="pre">MongoReplicaSetClient</span></tt></a>
created with <tt class="docutils literal"><span class="pre">use_greenlets=True</span></tt> will also use a greenlet-aware pool.
Additionally, it will use a background greenlet instead of a background thread
to monitor the state of the replica set.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">gevent</span> <span class="kn">import</span> <span class="n">monkey</span><span class="p">;</span> <span class="n">monkey</span><span class="o">.</span><span class="n">patch_socket</span><span class="p">()</span>
<span class="gp">>>> </span><span class="kn">from</span> <span class="nn">pymongo.mongo_replica_set_client</span> <span class="kn">import</span> <span class="n">MongoReplicaSetClient</span>
<span class="gp">>>> </span><span class="n">rsc</span> <span class="o">=</span> <span class="n">MongoReplicaSetClient</span><span class="p">(</span>
<span class="gp">... </span> <span class="s">'mongodb://localhost:27017,localhost:27018,localhost:27019'</span><span class="p">,</span>
<span class="gp">... </span> <span class="n">replicaSet</span><span class="o">=</span><span class="s">'repl0'</span><span class="p">,</span> <span class="n">use_greenlets</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
</pre></div>
</div>
<p>Setting <tt class="docutils literal"><span class="pre">use_greenlets</span></tt> is unnecessary under normal circumstances; simply call
<tt class="docutils literal"><span class="pre">patch_all</span></tt> to use Gevent with PyMongo.</p>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<h3><a href="../index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Gevent</a><ul>
<li><a class="reference internal" href="#using-gevent-with-threads">Using Gevent With Threads</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="../python3.html"
title="previous chapter">Python 3 FAQ</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="requests.html"
title="next chapter">Requests</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/examples/gevent.txt"
rel="nofollow">Show Source</a></li>
</ul>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="../search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<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>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="requests.html" title="Requests"
>next</a> |</li>
<li class="right" >
<a href="../python3.html" title="Python 3 FAQ"
>previous</a> |</li>
<li><a href="../index.html">PyMongo 2.6.3 documentation</a> »</li>
<li><a href="../changelog.html" >Changelog</a> »</li>
</ul>
</div>
<div class="footer">
© Copyright 2008 - 2012, 10gen, Inc..
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.
</div>
</body>
</html>
|