/usr/share/doc/python3-postgresql/html/alock.html is in python3-postgresql 1.0.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | <!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>Advisory Locks — py-postgresql v1.0.2 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: '1.0.2',
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>
<link rel="top" title="py-postgresql v1.0.2 documentation" href="index.html" />
<link rel="next" title="Cluster Management" href="cluster.html" />
<link rel="prev" title="Notification Management" href="notifyman.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="cluster.html" title="Cluster Management"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="notifyman.html" title="Notification Management"
accesskey="P">previous</a> |</li>
<li><a href="index.html">py-postgresql v1.0.2 documentation</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="advisory-locks">
<span id="alock"></span><h1>Advisory Locks<a class="headerlink" href="#advisory-locks" title="Permalink to this headline">¶</a></h1>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last"><cite>postgresql.alock</cite> is a new feature in v1.0.</p>
</div>
<p><a class="reference external" href="http://www.postgresql.org/docs/current/static/explicit-locking.html#ADVISORY-LOCKS">Explicit Locking in PostgreSQL</a>.</p>
<p>PostgreSQL’s advisory locks offer a cooperative synchronization primitive.
These are used in cases where an application needs access to a resource, but
using table locks may cause interference with other operations that can be
safely performed alongside the application-level, exclusive operation.</p>
<p>Advisory locks can be used by directly executing the stored procedures in the
database or by using the <tt class="xref py py-class docutils literal"><span class="pre">postgresql.alock.ALock</span></tt> subclasses, which
provides a context manager that uses those stored procedures.</p>
<p>Currently, only two subclasses exist. Each represents the lock mode
supported by PostgreSQL’s advisory locks:</p>
<blockquote>
<div><ul class="simple">
<li><tt class="xref py py-class docutils literal"><span class="pre">postgresql.alock.ShareLock</span></tt></li>
<li><tt class="xref py py-class docutils literal"><span class="pre">postgresql.alock.ExclusiveLock</span></tt></li>
</ul>
</div></blockquote>
<div class="section" id="acquiring-alocks">
<h2>Acquiring ALocks<a class="headerlink" href="#acquiring-alocks" title="Permalink to this headline">¶</a></h2>
<p>An ALock instance represents a sequence of advisory locks. A single ALock can
acquire and release multiple advisory locks by creating the instance with
multiple lock identifiers:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">postgresql</span> <span class="kn">import</span> <span class="n">alock</span>
<span class="gp">>>> </span><span class="n">table1_oid</span> <span class="o">=</span> <span class="mi">192842</span>
<span class="gp">>>> </span><span class="n">table2_oid</span> <span class="o">=</span> <span class="mi">192849</span>
<span class="gp">>>> </span><span class="n">l</span> <span class="o">=</span> <span class="n">alock</span><span class="o">.</span><span class="n">ExclusiveLock</span><span class="p">(</span><span class="n">db</span><span class="p">,</span> <span class="p">(</span><span class="n">table1_oid</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="n">table2_oid</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span>
<span class="gp">>>> </span><span class="n">l</span><span class="o">.</span><span class="n">acquire</span><span class="p">()</span>
<span class="gp">>>> </span><span class="o">...</span>
<span class="gp">>>> </span><span class="n">l</span><span class="o">.</span><span class="n">release</span><span class="p">()</span>
</pre></div>
</div>
<p><tt class="xref py py-class docutils literal"><span class="pre">postgresql.alock.ALock</span></tt> is similar to <tt class="xref py py-class docutils literal"><span class="pre">threading.RLock</span></tt>; in
order for an ALock to be released, it must be released the number of times it
has been acquired. ALocks are associated with and survived by their session.
Much like how RLocks are associated with the thread they are acquired in:
acquiring an ALock again will merely increment its count.</p>
<p>PostgreSQL allows advisory locks to be identified using a pair of <cite>int4</cite> or a
single <cite>int8</cite>. ALock instances represent a <em>sequence</em> of those identifiers:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">postgresql</span> <span class="kn">import</span> <span class="n">alock</span>
<span class="gp">>>> </span><span class="n">ids</span> <span class="o">=</span> <span class="p">[(</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">),</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span>
<span class="gp">>>> </span><span class="k">with</span> <span class="n">alock</span><span class="o">.</span><span class="n">ShareLock</span><span class="p">(</span><span class="n">db</span><span class="p">,</span> <span class="o">*</span><span class="n">ids</span><span class="p">):</span>
<span class="gp">... </span> <span class="o">...</span>
</pre></div>
</div>
<p>Both types of identifiers may be used within the same ALock, and, regardless of
their type, will be aquired in the order that they were given to the class’
constructor. In the above example, <tt class="docutils literal"><span class="pre">(0,0)</span></tt> is acquired first, then <tt class="docutils literal"><span class="pre">0</span></tt>, and
lastly <tt class="docutils literal"><span class="pre">1</span></tt>.</p>
</div>
<div class="section" id="alocks">
<h2>ALocks<a class="headerlink" href="#alocks" title="Permalink to this headline">¶</a></h2>
<p><cite>postgresql.alock.ALock</cite> is abstract; it defines the interface and some common
functionality. The lock mode is selected by choosing the appropriate subclass.</p>
<p>There are two:</p>
<blockquote>
<div><dl class="docutils">
<dt><tt class="docutils literal"><span class="pre">postgresql.alock.ExclusiveLock(database,</span> <span class="pre">*identifiers)</span></tt></dt>
<dd>Instantiate an ALock object representing the <cite>identifiers</cite> for use with the
<cite>database</cite>. Exclusive locks will conflict with other exclusive locks and share
locks.</dd>
<dt><tt class="docutils literal"><span class="pre">postgresql.alock.ShareLock(database,</span> <span class="pre">*identifiers)</span></tt></dt>
<dd>Instantiate an ALock object representing the <cite>identifiers</cite> for use with the
<cite>database</cite>. Share locks can be acquired when a share lock with the same
identifier has been acquired by another backend. However, an exclusive lock
with the same identifier will conflict.</dd>
</dl>
</div></blockquote>
<div class="section" id="alock-interface-points">
<h3>ALock Interface Points<a class="headerlink" href="#alock-interface-points" title="Permalink to this headline">¶</a></h3>
<p>Methods and properties available on <tt class="xref py py-class docutils literal"><span class="pre">postgresql.alock.ALock</span></tt> instances:</p>
<blockquote>
<div><dl class="docutils">
<dt><tt class="docutils literal"><span class="pre">alock.acquire(blocking</span> <span class="pre">=</span> <span class="pre">True)</span></tt></dt>
<dd><p class="first">Acquire the advisory locks represented by the <tt class="docutils literal"><span class="pre">alock</span></tt> object. If blocking is
<cite>True</cite>, the default, the method will block until locks on <em>all</em> the
identifiers have been acquired.</p>
<p class="last">If blocking is <cite>False</cite>, acquisition may not block, and success will be
indicated by the returned object: <cite>True</cite> if <em>all</em> lock identifiers were
acquired and <cite>False</cite> if any of the lock identifiers could not be acquired.</p>
</dd>
<dt><tt class="docutils literal"><span class="pre">alock.release()</span></tt></dt>
<dd>Release the advisory locks represented by the <tt class="docutils literal"><span class="pre">alock</span></tt> object. If the lock
has not been acquired, a <cite>RuntimeError</cite> will be raised.</dd>
<dt><tt class="docutils literal"><span class="pre">alock.locked()</span></tt></dt>
<dd>Returns a boolean describing whether the locks are held or not. This will
return <cite>False</cite> if the lock connection has been closed.</dd>
<dt><tt class="docutils literal"><span class="pre">alock.__enter__()</span></tt></dt>
<dd>Alias to <tt class="docutils literal"><span class="pre">acquire</span></tt>; context manager protocol. Always blocking.</dd>
<dt><tt class="docutils literal"><span class="pre">alock.__exit__(typ,</span> <span class="pre">val,</span> <span class="pre">tb)</span></tt></dt>
<dd>Alias to <tt class="docutils literal"><span class="pre">release</span></tt>; context manager protocol.</dd>
</dl>
</div></blockquote>
</div>
</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="#">Advisory Locks</a><ul>
<li><a class="reference internal" href="#acquiring-alocks">Acquiring ALocks</a></li>
<li><a class="reference internal" href="#alocks">ALocks</a><ul>
<li><a class="reference internal" href="#alock-interface-points">ALock Interface Points</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="notifyman.html"
title="previous chapter">Notification Management</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="cluster.html"
title="next chapter">Cluster Management</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/alock.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" size="18" />
<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="cluster.html" title="Cluster Management"
>next</a> |</li>
<li class="right" >
<a href="notifyman.html" title="Notification Management"
>previous</a> |</li>
<li><a href="index.html">py-postgresql v1.0.2 documentation</a> »</li>
</ul>
</div>
<div class="footer">
© Copyright 2010, James William Pye <x@jwp.name>.
Last updated on May 04, 2011.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.7.
</div>
</body>
</html>
|