580 lines
53 KiB
HTML
580 lines
53 KiB
HTML
|
||
<!DOCTYPE html>
|
||
|
||
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_CN">
|
||
<head>
|
||
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||
|
||
<title>操作系统实用工具 — Python 3.8.20 文档</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
|
||
<link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
|
||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||
|
||
<script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
|
||
<script src="../_static/jquery.js"></script>
|
||
<script src="../_static/underscore.js"></script>
|
||
<script src="../_static/doctools.js"></script>
|
||
<script src="../_static/language_data.js"></script>
|
||
<script src="../_static/translations.js"></script>
|
||
|
||
<script src="../_static/sidebar.js"></script>
|
||
|
||
<link rel="search" type="application/opensearchdescription+xml"
|
||
title="在 Python 3.8.20 文档 中搜索"
|
||
href="../_static/opensearch.xml"/>
|
||
<link rel="author" title="关于这些文档" href="../about.html" />
|
||
<link rel="index" title="索引" href="../genindex.html" />
|
||
<link rel="search" title="搜索" href="../search.html" />
|
||
<link rel="copyright" title="版权所有" href="../copyright.html" />
|
||
<link rel="next" title="导入模块" href="import.html" />
|
||
<link rel="prev" title="工具" href="utilities.html" />
|
||
<link rel="canonical" href="https://docs.python.org/3/c-api/sys.html" />
|
||
|
||
|
||
|
||
|
||
|
||
<style>
|
||
@media only screen {
|
||
table.full-width-table {
|
||
width: 100%;
|
||
}
|
||
}
|
||
</style>
|
||
<link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
|
||
<script type="text/javascript" src="../_static/copybutton.js"></script>
|
||
<script type="text/javascript" src="../_static/menu.js"></script>
|
||
|
||
</head>
|
||
<body>
|
||
<div class="mobile-nav">
|
||
<input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
|
||
aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
|
||
<label for="menuToggler" class="toggler__label">
|
||
<span></span>
|
||
</label>
|
||
<nav class="nav-content" role="navigation">
|
||
<a href="https://www.python.org/" class="nav-logo">
|
||
<img src="../_static/py.svg" alt="Logo"/>
|
||
</a>
|
||
<div class="version_switcher_placeholder"></div>
|
||
<form role="search" class="search" action="../search.html" method="get">
|
||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
|
||
<path fill-rule="nonzero"
|
||
d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z" fill="#444"></path>
|
||
</svg>
|
||
<input type="text" name="q" aria-label="快速搜索"/>
|
||
<input type="submit" value="转向"/>
|
||
</form>
|
||
</nav>
|
||
<div class="menu-wrapper">
|
||
<nav class="menu" role="navigation" aria-label="main navigation">
|
||
<div class="language_switcher_placeholder"></div>
|
||
<h3><a href="../contents.html">目录</a></h3>
|
||
<ul>
|
||
<li><a class="reference internal" href="#">操作系统实用工具</a></li>
|
||
<li><a class="reference internal" href="#system-functions">系统功能</a></li>
|
||
<li><a class="reference internal" href="#process-control">过程控制</a></li>
|
||
</ul>
|
||
|
||
<h4>上一个主题</h4>
|
||
<p class="topless"><a href="utilities.html"
|
||
title="上一章">工具</a></p>
|
||
<h4>下一个主题</h4>
|
||
<p class="topless"><a href="import.html"
|
||
title="下一章">导入模块</a></p>
|
||
<div role="note" aria-label="source link">
|
||
<h3>本页</h3>
|
||
<ul class="this-page-menu">
|
||
<li><a href="../bugs.html">报告 Bug</a></li>
|
||
<li>
|
||
<a href="https://github.com/python/cpython/blob/3.8/Doc/c-api/sys.rst"
|
||
rel="nofollow">显示源代码
|
||
</a>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
</nav>
|
||
</div>
|
||
</div>
|
||
|
||
<div id="outdated-warning" style="padding: .5em; text-align: center; background-color: #FFBABA; color: #6A0E0E;">
|
||
这个文档所针对的是一个已不再受支持的 Python 旧版本。
|
||
你应当升级版本,并阅读
|
||
<a href="/3/c-api/sys.html"> Python 当前稳定版本的文档</a>.
|
||
</div>
|
||
|
||
<div class="related" role="navigation" aria-label="related navigation">
|
||
<h3>导航</h3>
|
||
<ul>
|
||
<li class="right" style="margin-right: 10px">
|
||
<a href="../genindex.html" title="总目录"
|
||
accesskey="I">索引</a></li>
|
||
<li class="right" >
|
||
<a href="../py-modindex.html" title="Python 模块索引"
|
||
>模块</a> |</li>
|
||
<li class="right" >
|
||
<a href="import.html" title="导入模块"
|
||
accesskey="N">下一页</a> |</li>
|
||
<li class="right" >
|
||
<a href="utilities.html" title="工具"
|
||
accesskey="P">上一页</a> |</li>
|
||
|
||
<li><img src="../_static/py.svg" alt="python logo" style="vertical-align: middle; margin-top: -1px"/></li>
|
||
<li><a href="https://www.python.org/">Python</a> »</li>
|
||
<li class="switchers">
|
||
<div class="language_switcher_placeholder"></div>
|
||
<div class="version_switcher_placeholder"></div>
|
||
</li>
|
||
<li>
|
||
|
||
</li>
|
||
<li id="cpython-language-and-version">
|
||
<a href="../index.html">3.8.20 Documentation</a> »
|
||
</li>
|
||
|
||
<li class="nav-item nav-item-1"><a href="index.html" >Python/C API 参考手册</a> »</li>
|
||
<li class="nav-item nav-item-2"><a href="utilities.html" accesskey="U">工具</a> »</li>
|
||
<li class="right">
|
||
|
||
|
||
<div class="inline-search" role="search">
|
||
<form class="inline-search" action="../search.html" method="get">
|
||
<input placeholder="快速搜索" aria-label="快速搜索" type="text" name="q" />
|
||
<input type="submit" value="转向" />
|
||
<input type="hidden" name="check_keywords" value="yes" />
|
||
<input type="hidden" name="area" value="default" />
|
||
</form>
|
||
</div>
|
||
|
|
||
</li>
|
||
|
||
</ul>
|
||
</div>
|
||
|
||
<div class="document">
|
||
<div class="documentwrapper">
|
||
<div class="bodywrapper">
|
||
<div class="body" role="main">
|
||
|
||
<section id="operating-system-utilities">
|
||
<span id="os"></span><h1>操作系统实用工具<a class="headerlink" href="#operating-system-utilities" title="永久链接至标题">¶</a></h1>
|
||
<dl class="function">
|
||
<dt id="c.PyOS_FSPath">
|
||
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="sig-name descname">PyOS_FSPath</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *path</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyOS_FSPath" title="永久链接至目标">¶</a></dt>
|
||
<dd><em class="refcount">Return value: New reference.</em><p>返回 <em>path</em> 在文件系统中的表示形式。 如果该对象是一个 <a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a> 或 <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> 对象,则它的引用计数将会增加。 如果该对象实现了 <a class="reference internal" href="../library/os.html#os.PathLike" title="os.PathLike"><code class="xref py py-class docutils literal notranslate"><span class="pre">os.PathLike</span></code></a> 接口,则只要它是一个 <a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a> 或 <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> 对象就将返回 <a class="reference internal" href="../library/os.html#os.PathLike.__fspath__" title="os.PathLike.__fspath__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__fspath__()</span></code></a>。 在其他情况下将引发 <a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a> 并返回 <code class="docutils literal notranslate"><span class="pre">NULL</span></code>。</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">3.6 新版功能.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="c.Py_FdIsInteractive">
|
||
int <code class="sig-name descname">Py_FdIsInteractive</code><span class="sig-paren">(</span>FILE<em> *fp</em>, const char<em> *filename</em><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_FdIsInteractive" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>如果名称为 <em>filename</em> 的标准 I/O 文件 <em>fp</em> 被确认为可交互的则返回真(非零)值。 <code class="docutils literal notranslate"><span class="pre">isatty(fileno(fp))</span></code> 为真值的文件均属于这种情况。 如果全局旗标 <a class="reference internal" href="init.html#c.Py_InteractiveFlag" title="Py_InteractiveFlag"><code class="xref c c-data docutils literal notranslate"><span class="pre">Py_InteractiveFlag</span></code></a> 为真值,此函数在 <em>filename</em> 指针为 <code class="docutils literal notranslate"><span class="pre">NULL</span></code> 或者其名称等于字符串 <code class="docutils literal notranslate"><span class="pre">'<stdin>'</span></code> 或 <code class="docutils literal notranslate"><span class="pre">'???'</span></code> 时也将返回真值。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="c.PyOS_BeforeFork">
|
||
void <code class="sig-name descname">PyOS_BeforeFork</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyOS_BeforeFork" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>在进程分叉之前准备某些内部状态的函数。 此函数应当在调用 <code class="xref c c-func docutils literal notranslate"><span class="pre">fork()</span></code> 或者任何类似的克隆当前进程的函数之前被调用。 只适用于定义了 <code class="xref c c-func docutils literal notranslate"><span class="pre">fork()</span></code> 的系统。</p>
|
||
<div class="admonition warning">
|
||
<p class="admonition-title">警告</p>
|
||
<p>C <code class="xref c c-func docutils literal notranslate"><span class="pre">fork()</span></code> 调用应当只在 <a class="reference internal" href="init.html#fork-and-threads"><span class="std std-ref">"main" 线程</span></a> (位于 <a class="reference internal" href="init.html#sub-interpreter-support"><span class="std std-ref">"main" 解释器</span></a>) 中进行。 对于 <code class="docutils literal notranslate"><span class="pre">PyOS_BeforeFork()</span></code> 来说也是如此。</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">3.7 新版功能.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="c.PyOS_AfterFork_Parent">
|
||
void <code class="sig-name descname">PyOS_AfterFork_Parent</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyOS_AfterFork_Parent" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>在进程分叉之后更新某些内部状态的函数。 此函数应当在调用 <code class="xref c c-func docutils literal notranslate"><span class="pre">fork()</span></code> 或任何类似的克隆当前进程的函数之后被调用,无论进程克隆是否成功。 只适用于定义了 <code class="xref c c-func docutils literal notranslate"><span class="pre">fork()</span></code> 的系统。</p>
|
||
<div class="admonition warning">
|
||
<p class="admonition-title">警告</p>
|
||
<p>C <code class="xref c c-func docutils literal notranslate"><span class="pre">fork()</span></code> 调用应当只在 <a class="reference internal" href="init.html#fork-and-threads"><span class="std std-ref">"main" 线程</span></a> (位于 <a class="reference internal" href="init.html#sub-interpreter-support"><span class="std std-ref">"main" 解释器</span></a>) 中进行。 对于 <code class="docutils literal notranslate"><span class="pre">PyOS_AfterFork_Parent()</span></code> 来说也是如此。</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">3.7 新版功能.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="c.PyOS_AfterFork_Child">
|
||
void <code class="sig-name descname">PyOS_AfterFork_Child</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyOS_AfterFork_Child" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>在进程分叉之后更新内部解释器状态的函数。 此函数必须在调用 <code class="xref c c-func docutils literal notranslate"><span class="pre">fork()</span></code> 或任何类似的克隆当前进程的函数之后在子进程中被调用,如果该进程有机会回调到 Python 解释器的话。 只适用于定义了 <code class="xref c c-func docutils literal notranslate"><span class="pre">fork()</span></code> 的系统。</p>
|
||
<div class="admonition warning">
|
||
<p class="admonition-title">警告</p>
|
||
<p>C <code class="xref c c-func docutils literal notranslate"><span class="pre">fork()</span></code> 调用应当只在 <a class="reference internal" href="init.html#fork-and-threads"><span class="std std-ref">"main" 线程</span></a> (位于 <a class="reference internal" href="init.html#sub-interpreter-support"><span class="std std-ref">"main" 解释器</span></a>) 中进行。 对于 <code class="docutils literal notranslate"><span class="pre">PyOS_AfterFork_Child()</span></code> 来说也是如此。</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">3.7 新版功能.</span></p>
|
||
</div>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">参见</p>
|
||
<p><a class="reference internal" href="../library/os.html#os.register_at_fork" title="os.register_at_fork"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.register_at_fork()</span></code></a> 允许注册可被 <a class="reference internal" href="#c.PyOS_BeforeFork" title="PyOS_BeforeFork"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyOS_BeforeFork()</span></code></a>, <a class="reference internal" href="#c.PyOS_AfterFork_Parent" title="PyOS_AfterFork_Parent"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyOS_AfterFork_Parent()</span></code></a> 和 <a class="reference internal" href="#c.PyOS_AfterFork_Child" title="PyOS_AfterFork_Child"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyOS_AfterFork_Child()</span></code></a> 调用的自定义 Python 函数。</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="c.PyOS_AfterFork">
|
||
void <code class="sig-name descname">PyOS_AfterFork</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyOS_AfterFork" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>在进程分叉之后更新某些内部状态的函数;如果要继续使用 Python 解释器则此函数应当在新进程中被调用。 如果已将一个新的可执行文件载入到新进程中,则不需要调用此函数。</p>
|
||
<div class="deprecated">
|
||
<p><span class="versionmodified deprecated">3.7 版后已移除: </span>此函数已被 <a class="reference internal" href="#c.PyOS_AfterFork_Child" title="PyOS_AfterFork_Child"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyOS_AfterFork_Child()</span></code></a> 取代。</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="c.PyOS_CheckStack">
|
||
int <code class="sig-name descname">PyOS_CheckStack</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyOS_CheckStack" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>当解释器的栈空间耗尽时返回真值。 这是一个可靠的检查,但仅在定义了 <code class="xref py py-const docutils literal notranslate"><span class="pre">USE_STACKCHECK</span></code> 时可用(目前在 Windows 上使用 Microsoft Visual C++ 编译器)。 <code class="xref py py-const docutils literal notranslate"><span class="pre">USE_STACKCHECK</span></code> 将被自动定义;你绝不应该在你自己的代码中改变此定义。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="c.PyOS_getsig">
|
||
PyOS_sighandler_t <code class="sig-name descname">PyOS_getsig</code><span class="sig-paren">(</span>int<em> i</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyOS_getsig" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>返回当前用于信号 <em>i</em> 的信号处理器。 这是一个对 <code class="xref c c-func docutils literal notranslate"><span class="pre">sigaction()</span></code> 或 <code class="xref c c-func docutils literal notranslate"><span class="pre">signal()</span></code> 简单包装器。 请不要直接调用那两个函数! <code class="xref c c-type docutils literal notranslate"><span class="pre">PyOS_sighandler_t</span></code> 是对应于 <code class="xref c c-type docutils literal notranslate"><span class="pre">void</span> <span class="pre">(*)(int)</span></code> 的 typedef 别名。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="c.PyOS_setsig">
|
||
PyOS_sighandler_t <code class="sig-name descname">PyOS_setsig</code><span class="sig-paren">(</span>int<em> i</em>, PyOS_sighandler_t<em> h</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyOS_setsig" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>将用于信号 <em>i</em> 的信号处理器设为 <em>h</em>;返回旧的信号处理器。 这是一个对 <code class="xref c c-func docutils literal notranslate"><span class="pre">sigaction()</span></code> 或 <code class="xref c c-func docutils literal notranslate"><span class="pre">signal()</span></code> 的简单包装器。 请不要直接调用那两个函数! <code class="xref c c-type docutils literal notranslate"><span class="pre">PyOS_sighandler_t</span></code> 是对应于 <code class="xref c c-type docutils literal notranslate"><span class="pre">void</span> <span class="pre">(*)(int)</span></code> 的 typedef 别名。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="c.Py_DecodeLocale">
|
||
wchar_t* <code class="sig-name descname">Py_DecodeLocale</code><span class="sig-paren">(</span>const char*<em> arg</em>, size_t<em> *size</em><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_DecodeLocale" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>Decode a byte string from the locale encoding with the <a class="reference internal" href="../library/codecs.html#surrogateescape"><span class="std std-ref">surrogateescape
|
||
error handler</span></a>: undecodable bytes are decoded as
|
||
characters in range U+DC80..U+DCFF. If a byte sequence can be decoded as a
|
||
surrogate character, escape the bytes using the surrogateescape error
|
||
handler instead of decoding them.</p>
|
||
<p>Encoding, highest priority to lowest priority:</p>
|
||
<ul class="simple">
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">UTF-8</span></code> on macOS, Android, and VxWorks;</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">UTF-8</span></code> on Windows if <a class="reference internal" href="init.html#c.Py_LegacyWindowsFSEncodingFlag" title="Py_LegacyWindowsFSEncodingFlag"><code class="xref c c-data docutils literal notranslate"><span class="pre">Py_LegacyWindowsFSEncodingFlag</span></code></a> is zero;</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">UTF-8</span></code> if the Python UTF-8 mode is enabled;</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">ASCII</span></code> if the <code class="docutils literal notranslate"><span class="pre">LC_CTYPE</span></code> locale is <code class="docutils literal notranslate"><span class="pre">"C"</span></code>,
|
||
<code class="docutils literal notranslate"><span class="pre">nl_langinfo(CODESET)</span></code> returns the <code class="docutils literal notranslate"><span class="pre">ASCII</span></code> encoding (or an alias),
|
||
and <code class="xref c c-func docutils literal notranslate"><span class="pre">mbstowcs()</span></code> and <code class="xref c c-func docutils literal notranslate"><span class="pre">wcstombs()</span></code> functions uses the
|
||
<code class="docutils literal notranslate"><span class="pre">ISO-8859-1</span></code> encoding.</p></li>
|
||
<li><p>the current locale encoding.</p></li>
|
||
</ul>
|
||
<p>返回一个指向新分配的由宽字符组成的字符串的指针,使用 <a class="reference internal" href="memory.html#c.PyMem_RawFree" title="PyMem_RawFree"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMem_RawFree()</span></code></a> 来释放内存。 如果 size 不为 <code class="docutils literal notranslate"><span class="pre">NULL</span></code>,则将排除了 null 字符的宽字符数量写入到 <code class="docutils literal notranslate"><span class="pre">*size</span></code></p>
|
||
<p>在解码错误或内存分配错误时返回 <code class="docutils literal notranslate"><span class="pre">NULL</span></code>。 如果 <em>size</em> 不为 <code class="docutils literal notranslate"><span class="pre">NULL</span></code>,则 <code class="docutils literal notranslate"><span class="pre">*size</span></code> 将在内存错误时设为 <code class="docutils literal notranslate"><span class="pre">(size_t)-1</span></code> 或在解码错误时设为 <code class="docutils literal notranslate"><span class="pre">(size_t)-2</span></code>。</p>
|
||
<p>解码错误绝对不应当发生,除非 C 库有程序缺陷。</p>
|
||
<p>请使用 <a class="reference internal" href="#c.Py_EncodeLocale" title="Py_EncodeLocale"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_EncodeLocale()</span></code></a> 函数来将字符串编码回字节串。</p>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">参见</p>
|
||
<p><a class="reference internal" href="unicode.html#c.PyUnicode_DecodeFSDefaultAndSize" title="PyUnicode_DecodeFSDefaultAndSize"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_DecodeFSDefaultAndSize()</span></code></a> 和 <a class="reference internal" href="unicode.html#c.PyUnicode_DecodeLocaleAndSize" title="PyUnicode_DecodeLocaleAndSize"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_DecodeLocaleAndSize()</span></code></a> 函数。</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">3.5 新版功能.</span></p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">在 3.7 版更改: </span>The function now uses the UTF-8 encoding in the UTF-8 mode.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">在 3.8 版更改: </span>现在如果在 Windows 上 <a class="reference internal" href="init.html#c.Py_LegacyWindowsFSEncodingFlag" title="Py_LegacyWindowsFSEncodingFlag"><code class="xref c c-data docutils literal notranslate"><span class="pre">Py_LegacyWindowsFSEncodingFlag</span></code></a> 为零则此函数将使用 UTF-8 编码格式;</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="c.Py_EncodeLocale">
|
||
char* <code class="sig-name descname">Py_EncodeLocale</code><span class="sig-paren">(</span>const wchar_t<em> *text</em>, size_t<em> *error_pos</em><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_EncodeLocale" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>Encode a wide character string to the locale encoding with the
|
||
<a class="reference internal" href="../library/codecs.html#surrogateescape"><span class="std std-ref">surrogateescape error handler</span></a>: surrogate characters
|
||
in the range U+DC80..U+DCFF are converted to bytes 0x80..0xFF.</p>
|
||
<p>Encoding, highest priority to lowest priority:</p>
|
||
<ul class="simple">
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">UTF-8</span></code> on macOS, Android, and VxWorks;</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">UTF-8</span></code> on Windows if <a class="reference internal" href="init.html#c.Py_LegacyWindowsFSEncodingFlag" title="Py_LegacyWindowsFSEncodingFlag"><code class="xref c c-data docutils literal notranslate"><span class="pre">Py_LegacyWindowsFSEncodingFlag</span></code></a> is zero;</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">UTF-8</span></code> if the Python UTF-8 mode is enabled;</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">ASCII</span></code> if the <code class="docutils literal notranslate"><span class="pre">LC_CTYPE</span></code> locale is <code class="docutils literal notranslate"><span class="pre">"C"</span></code>,
|
||
<code class="docutils literal notranslate"><span class="pre">nl_langinfo(CODESET)</span></code> returns the <code class="docutils literal notranslate"><span class="pre">ASCII</span></code> encoding (or an alias),
|
||
and <code class="xref c c-func docutils literal notranslate"><span class="pre">mbstowcs()</span></code> and <code class="xref c c-func docutils literal notranslate"><span class="pre">wcstombs()</span></code> functions uses the
|
||
<code class="docutils literal notranslate"><span class="pre">ISO-8859-1</span></code> encoding.</p></li>
|
||
<li><p>the current locale encoding.</p></li>
|
||
</ul>
|
||
<p>The function uses the UTF-8 encoding in the Python UTF-8 mode.</p>
|
||
<p>Return a pointer to a newly allocated byte string, use <a class="reference internal" href="memory.html#c.PyMem_Free" title="PyMem_Free"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMem_Free()</span></code></a>
|
||
to free the memory. Return <code class="docutils literal notranslate"><span class="pre">NULL</span></code> on encoding error or memory allocation
|
||
error</p>
|
||
<p>如果 error_pos 不为 <code class="docutils literal notranslate"><span class="pre">NULL</span></code>,则成功时会将 <code class="docutils literal notranslate"><span class="pre">*error_pos</span></code> 设为 <code class="docutils literal notranslate"><span class="pre">(size_t)-1</span></code>,或是在发生编码错误时设为无效字符的索引号。</p>
|
||
<p>请使用 <a class="reference internal" href="#c.Py_DecodeLocale" title="Py_DecodeLocale"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_DecodeLocale()</span></code></a> 函数来将字节串解码回由宽字符组成的字符串。</p>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">参见</p>
|
||
<p><a class="reference internal" href="unicode.html#c.PyUnicode_EncodeFSDefault" title="PyUnicode_EncodeFSDefault"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeFSDefault()</span></code></a> 和 <a class="reference internal" href="unicode.html#c.PyUnicode_EncodeLocale" title="PyUnicode_EncodeLocale"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeLocale()</span></code></a> 函数。</p>
|
||
</div>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">3.5 新版功能.</span></p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">在 3.7 版更改: </span>The function now uses the UTF-8 encoding in the UTF-8 mode.</p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">在 3.8 版更改: </span>现在如果在 Windows 上 <a class="reference internal" href="init.html#c.Py_LegacyWindowsFSEncodingFlag" title="Py_LegacyWindowsFSEncodingFlag"><code class="xref c c-data docutils literal notranslate"><span class="pre">Py_LegacyWindowsFSEncodingFlag</span></code></a> 为零则此函数将使用 UTF-8 编码格式;</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
</section>
|
||
<section id="system-functions">
|
||
<span id="systemfunctions"></span><h1>系统功能<a class="headerlink" href="#system-functions" title="永久链接至标题">¶</a></h1>
|
||
<p>这些是使来自 <a class="reference internal" href="../library/sys.html#module-sys" title="sys: Access system-specific parameters and functions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">sys</span></code></a> 模块的功能可以让 C 代码访问的工具函数。 它们都可用于当前解释器线程的 <a class="reference internal" href="../library/sys.html#module-sys" title="sys: Access system-specific parameters and functions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">sys</span></code></a> 模块的字典,该字典包含在内部线程状态结构体中。</p>
|
||
<dl class="function">
|
||
<dt id="c.PySys_GetObject">
|
||
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a> *<code class="sig-name descname">PySys_GetObject</code><span class="sig-paren">(</span>const char<em> *name</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PySys_GetObject" title="永久链接至目标">¶</a></dt>
|
||
<dd><em class="refcount">Return value: Borrowed reference.</em><p>返回来自 <a class="reference internal" href="../library/sys.html#module-sys" title="sys: Access system-specific parameters and functions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">sys</span></code></a> 模块的对象 <em>name</em> 或者如果它不存在则返回 <code class="docutils literal notranslate"><span class="pre">NULL</span></code>,并且不会设置异常。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="c.PySys_SetObject">
|
||
int <code class="sig-name descname">PySys_SetObject</code><span class="sig-paren">(</span>const char<em> *name</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *v</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PySys_SetObject" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>将 <a class="reference internal" href="../library/sys.html#module-sys" title="sys: Access system-specific parameters and functions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">sys</span></code></a> 模块中的 <em>name</em> 设为 <em>v</em> 除非 <em>v</em> 为 <code class="docutils literal notranslate"><span class="pre">NULL</span></code>,在此情况下 <em>name</em> 将从 sys 模块中被删除。 成功时返回 <code class="docutils literal notranslate"><span class="pre">0</span></code>,发生错误时返回 <code class="docutils literal notranslate"><span class="pre">-1</span></code>。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="c.PySys_ResetWarnOptions">
|
||
void <code class="sig-name descname">PySys_ResetWarnOptions</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#c.PySys_ResetWarnOptions" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>将 <a class="reference internal" href="../library/sys.html#sys.warnoptions" title="sys.warnoptions"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.warnoptions</span></code></a> 重置为空列表。 此函数可在 <a class="reference internal" href="init.html#c.Py_Initialize" title="Py_Initialize"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_Initialize()</span></code></a> 之前被调用。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="c.PySys_AddWarnOption">
|
||
void <code class="sig-name descname">PySys_AddWarnOption</code><span class="sig-paren">(</span>const wchar_t<em> *s</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PySys_AddWarnOption" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>将 <em>s</em> 添加到 <a class="reference internal" href="../library/sys.html#sys.warnoptions" title="sys.warnoptions"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.warnoptions</span></code></a>。 此函数必须在 <a class="reference internal" href="init.html#c.Py_Initialize" title="Py_Initialize"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_Initialize()</span></code></a> 之前被调用以便影响警告过滤器列表。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="c.PySys_AddWarnOptionUnicode">
|
||
void <code class="sig-name descname">PySys_AddWarnOptionUnicode</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *unicode</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PySys_AddWarnOptionUnicode" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>将 <em>unicode</em> 添加到 <a class="reference internal" href="../library/sys.html#sys.warnoptions" title="sys.warnoptions"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.warnoptions</span></code></a>。</p>
|
||
<p>注意:目前此函数不可在 CPython 实现之外使用,因为它必须在 <a class="reference internal" href="init.html#c.Py_Initialize" title="Py_Initialize"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_Initialize()</span></code></a> 中的 <a class="reference internal" href="../library/warnings.html#module-warnings" title="warnings: Issue warning messages and control their disposition."><code class="xref py py-mod docutils literal notranslate"><span class="pre">warnings</span></code></a> 显式导入之前被调用,但是要等运行时已初始化到足以允许创建 Unicode 对象时才能被调用。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="c.PySys_SetPath">
|
||
void <code class="sig-name descname">PySys_SetPath</code><span class="sig-paren">(</span>const wchar_t<em> *path</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PySys_SetPath" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>将 <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a> 设为由在 <em>path</em> 中找到的路径组成的列表对象,该参数应为使用特定平台的搜索路径分隔符 (在 Unix 上为 <code class="docutils literal notranslate"><span class="pre">:</span></code>,在 Windows 上为 <code class="docutils literal notranslate"><span class="pre">;</span></code>) 分隔的路径的列表。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="c.PySys_WriteStdout">
|
||
void <code class="sig-name descname">PySys_WriteStdout</code><span class="sig-paren">(</span>const char<em> *format</em>, ...<span class="sig-paren">)</span><a class="headerlink" href="#c.PySys_WriteStdout" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>将以 <em>format</em> 描述的输出字符串写入到 <a class="reference internal" href="../library/sys.html#sys.stdout" title="sys.stdout"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stdout</span></code></a>。 不会引发任何异常,即使发生了截断(见下文)。</p>
|
||
<p><em>format</em> 应当将已格式化的输出字符串的总大小限制在 1000 字节以下 -- 超过 1000 字节后,输出字符串会被截断。 特别地,这意味着不应出现不受限制的 "%s" 格式;它们应当使用 "%.<N>s" 来限制,其中 <N> 是一个经计算使得 <N> 与其他已格式化文本的最大尺寸之和不会超过 1000 字节的十进制数字。 还要注意 "%f",它可能为非常大的数字打印出数以百计的数位。</p>
|
||
<p>如果发生了错误,<a class="reference internal" href="../library/sys.html#sys.stdout" title="sys.stdout"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stdout</span></code></a> 会被清空,已格式化的消息将被写入到真正的 (C 层级) <em>stdout</em>。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="c.PySys_WriteStderr">
|
||
void <code class="sig-name descname">PySys_WriteStderr</code><span class="sig-paren">(</span>const char<em> *format</em>, ...<span class="sig-paren">)</span><a class="headerlink" href="#c.PySys_WriteStderr" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>类似 <a class="reference internal" href="#c.PySys_WriteStdout" title="PySys_WriteStdout"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySys_WriteStdout()</span></code></a>,但改为写入到 <a class="reference internal" href="../library/sys.html#sys.stderr" title="sys.stderr"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stderr</span></code></a> 或 <em>stderr</em>。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="c.PySys_FormatStdout">
|
||
void <code class="sig-name descname">PySys_FormatStdout</code><span class="sig-paren">(</span>const char<em> *format</em>, ...<span class="sig-paren">)</span><a class="headerlink" href="#c.PySys_FormatStdout" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>类似 PySys_WriteStdout() 的函数将会使用 <a class="reference internal" href="unicode.html#c.PyUnicode_FromFormatV" title="PyUnicode_FromFormatV"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FromFormatV()</span></code></a> 来格式化消息并且不会将消息截短至任意长度。</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">3.2 新版功能.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="c.PySys_FormatStderr">
|
||
void <code class="sig-name descname">PySys_FormatStderr</code><span class="sig-paren">(</span>const char<em> *format</em>, ...<span class="sig-paren">)</span><a class="headerlink" href="#c.PySys_FormatStderr" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>类似 <a class="reference internal" href="#c.PySys_FormatStdout" title="PySys_FormatStdout"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySys_FormatStdout()</span></code></a>,但改为写入到 <a class="reference internal" href="../library/sys.html#sys.stderr" title="sys.stderr"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stderr</span></code></a> 或 <em>stderr</em>。</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">3.2 新版功能.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="c.PySys_AddXOption">
|
||
void <code class="sig-name descname">PySys_AddXOption</code><span class="sig-paren">(</span>const wchar_t<em> *s</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PySys_AddXOption" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>将 <em>s</em> 解析为一个由 <a class="reference internal" href="../using/cmdline.html#id5"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span></code></a> 选项组成的集合并将它们添加到 <a class="reference internal" href="#c.PySys_GetXOptions" title="PySys_GetXOptions"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySys_GetXOptions()</span></code></a> 所返回的当前选项映射。 此函数可以在 <a class="reference internal" href="init.html#c.Py_Initialize" title="Py_Initialize"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_Initialize()</span></code></a> 之前被调用。</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">3.2 新版功能.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="c.PySys_GetXOptions">
|
||
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a> *<code class="sig-name descname">PySys_GetXOptions</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#c.PySys_GetXOptions" title="永久链接至目标">¶</a></dt>
|
||
<dd><em class="refcount">Return value: Borrowed reference.</em><p>返回当前 <a class="reference internal" href="../using/cmdline.html#id5"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span></code></a> 选项的字典,类似于 <a class="reference internal" href="../library/sys.html#sys._xoptions" title="sys._xoptions"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys._xoptions</span></code></a>。 发生错误时,将返回 <code class="docutils literal notranslate"><span class="pre">NULL</span></code> 并设置一个异常。</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">3.2 新版功能.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="c.PySys_Audit">
|
||
int <code class="sig-name descname">PySys_Audit</code><span class="sig-paren">(</span>const char<em> *event</em>, const char<em> *format</em>, ...<span class="sig-paren">)</span><a class="headerlink" href="#c.PySys_Audit" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>引发一个审计事件并附带任何激活的钩子。 成功时返回零值或在失败时返回非零值并设置一个异常。</p>
|
||
<p>如果已添加了任何钩子,则将使用 <em>format</em> 和其他参数来构造一个用入传入的元组。 除 <code class="docutils literal notranslate"><span class="pre">N</span></code> 以外,在 <a class="reference internal" href="arg.html#c.Py_BuildValue" title="Py_BuildValue"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_BuildValue()</span></code></a> 中使用的格式字符均可使用。 如果构建的值不是一个元组,它将被添加到一个单元素元组中。 (格式选项 <code class="docutils literal notranslate"><span class="pre">N</span></code> 会消耗一个引用,但是由于没有办法知道此函数的参数是否将被消耗,因此使用它可能导致引用泄漏。)</p>
|
||
<p>Note that <code class="docutils literal notranslate"><span class="pre">#</span></code> format characters should always be treated as
|
||
<code class="docutils literal notranslate"><span class="pre">Py_ssize_t</span></code>, regardless of whether <code class="docutils literal notranslate"><span class="pre">PY_SSIZE_T_CLEAN</span></code> was defined.</p>
|
||
<p><a class="reference internal" href="../library/sys.html#sys.audit" title="sys.audit"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.audit()</span></code></a> 会执行与来自 Python 代码的函数相同的操作。</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">3.8 新版功能.</span></p>
|
||
</div>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">在 3.8.2 版更改: </span>Require <code class="docutils literal notranslate"><span class="pre">Py_ssize_t</span></code> for <code class="docutils literal notranslate"><span class="pre">#</span></code> format characters. Previously, an
|
||
unavoidable deprecation warning was raised.</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="c.PySys_AddAuditHook">
|
||
int <code class="sig-name descname">PySys_AddAuditHook</code><span class="sig-paren">(</span>Py_AuditHookFunction<em> hook</em>, void<em> *userData</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PySys_AddAuditHook" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>Append the callable <em>hook</em> to the list of active auditing hooks.
|
||
Return zero for success
|
||
and non-zero on failure. If the runtime has been initialized, also set an
|
||
error on failure. Hooks added through this API are called for all
|
||
interpreters created by the runtime.</p>
|
||
<p><em>userData</em> 指针会被传入钩子函数。 因于钩子函数可能由不同的运行时调用,该指针不应直接指向 Python 状态。</p>
|
||
<p>此函数可在 <a class="reference internal" href="init.html#c.Py_Initialize" title="Py_Initialize"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_Initialize()</span></code></a> 之前被安全地调用。 如果在运行时初始化之后被调用,现有的审计钩子将得到通知并可能通过引发一个从 <a class="reference internal" href="../library/exceptions.html#Exception" title="Exception"><code class="xref py py-class docutils literal notranslate"><span class="pre">Exception</span></code></a> 子类化的错误静默地放弃操作(其他错误将不会被静默)。</p>
|
||
<p>钩子函数的类型为 <code class="xref c c-type docutils literal notranslate"><span class="pre">int</span> <span class="pre">(*)(const</span> <span class="pre">char</span> <span class="pre">*event,</span> <span class="pre">PyObject</span> <span class="pre">*args,</span> <span class="pre">void</span> <span class="pre">*userData)</span></code>,其中 <em>args</em> 保证是一个 <a class="reference internal" href="tuple.html#c.PyTupleObject" title="PyTupleObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyTupleObject</span></code></a>。 钩子函数调用时总是附带引发该事件的 Python 解释器所持有的 GIL。</p>
|
||
<p>请参阅 <span class="target" id="index-5"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0578"><strong>PEP 578</strong></a> 了解有关审计的详细描述。 在运行时和标准库中会引发审计事件的函数清单见 <a class="reference internal" href="../library/audit_events.html#audit-events"><span class="std std-ref">审计事件表</span></a>。 更多细节见每个函数的文档。</p>
|
||
<p class="audit-hook"><p>如果解释器已被初始化,此函数将引发审计事件 <code class="docutils literal notranslate"><span class="pre">sys.addaudithook</span></code> 且不附带任何参数。 如果有任何现存的钩子引发了一个派生自 <a class="reference internal" href="../library/exceptions.html#Exception" title="Exception"><code class="xref py py-class docutils literal notranslate"><span class="pre">Exception</span></code></a> 的异常,新的钩子将不会被添加且该异常会被清除。 因此,调用方不可假定他们的钩子已被添加除非他们能控制所有现存的钩子。</p>
|
||
</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">3.8 新版功能.</span></p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
</section>
|
||
<section id="process-control">
|
||
<span id="processcontrol"></span><h1>过程控制<a class="headerlink" href="#process-control" title="永久链接至标题">¶</a></h1>
|
||
<dl class="function">
|
||
<dt id="c.Py_FatalError">
|
||
void <code class="sig-name descname">Py_FatalError</code><span class="sig-paren">(</span>const char<em> *message</em><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_FatalError" title="永久链接至目标">¶</a></dt>
|
||
<dd><p id="index-1">打印一个致命错误消息并杀掉进程。 不会执行任何清理。 此函数应当仅在检测到可能令继续使用 Python 解释器变得危险的条件时被发起调用;例如,当对象管理已被破坏的时候。 在 Unix 上,标准 C 库函数 <code class="xref c c-func docutils literal notranslate"><span class="pre">abort()</span></code> 会被调用并将由它来尝试产生一个 <code class="file docutils literal notranslate"><span class="pre">core</span></code> 文件。</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="c.Py_Exit">
|
||
void <code class="sig-name descname">Py_Exit</code><span class="sig-paren">(</span>int<em> status</em><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_Exit" title="永久链接至目标">¶</a></dt>
|
||
<dd><p id="index-2">退出当前进程。 这将调用 <a class="reference internal" href="init.html#c.Py_FinalizeEx" title="Py_FinalizeEx"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_FinalizeEx()</span></code></a> 然后再调用标准 C 库函数 <code class="docutils literal notranslate"><span class="pre">exit(status)</span></code>。 如果 <a class="reference internal" href="init.html#c.Py_FinalizeEx" title="Py_FinalizeEx"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_FinalizeEx()</span></code></a> 提示错误,退出状态将被设为 120。</p>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">在 3.6 版更改: </span>来自最终化的错误不会再被忽略。</p>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="c.Py_AtExit">
|
||
int <code class="sig-name descname">Py_AtExit</code><span class="sig-paren">(</span>void (<em>*func</em>)()<span class="sig-paren">)</span><a class="headerlink" href="#c.Py_AtExit" title="永久链接至目标">¶</a></dt>
|
||
<dd><p id="index-3">注册一个由 <a class="reference internal" href="init.html#c.Py_FinalizeEx" title="Py_FinalizeEx"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_FinalizeEx()</span></code></a> 调用的清理函数。 调用清理函数将不传入任何参数且不应返回任何值。 最多可以注册32 个清理函数。 当注册成功时,<a class="reference internal" href="#c.Py_AtExit" title="Py_AtExit"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_AtExit()</span></code></a> 将返回 <code class="docutils literal notranslate"><span class="pre">0</span></code>;失败时,它将返回 <code class="docutils literal notranslate"><span class="pre">-1</span></code>。 最后注册的清理函数会最先被调用。 每个清理函数将至多被调用一次。 由于 Python 的内部最终化将在清理函数之前完成,因此 Python API 不应被 <em>func</em> 调用。</p>
|
||
</dd></dl>
|
||
|
||
</section>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||
<div class="sphinxsidebarwrapper">
|
||
<h3><a href="../contents.html">目录</a></h3>
|
||
<ul>
|
||
<li><a class="reference internal" href="#">操作系统实用工具</a></li>
|
||
<li><a class="reference internal" href="#system-functions">系统功能</a></li>
|
||
<li><a class="reference internal" href="#process-control">过程控制</a></li>
|
||
</ul>
|
||
|
||
<h4>上一个主题</h4>
|
||
<p class="topless"><a href="utilities.html"
|
||
title="上一章">工具</a></p>
|
||
<h4>下一个主题</h4>
|
||
<p class="topless"><a href="import.html"
|
||
title="下一章">导入模块</a></p>
|
||
<div role="note" aria-label="source link">
|
||
<h3>本页</h3>
|
||
<ul class="this-page-menu">
|
||
<li><a href="../bugs.html">报告 Bug</a></li>
|
||
<li>
|
||
<a href="https://github.com/python/cpython/blob/3.8/Doc/c-api/sys.rst"
|
||
rel="nofollow">显示源代码
|
||
</a>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="clearer"></div>
|
||
</div>
|
||
<div class="related" role="navigation" aria-label="related navigation">
|
||
<h3>导航</h3>
|
||
<ul>
|
||
<li class="right" style="margin-right: 10px">
|
||
<a href="../genindex.html" title="总目录"
|
||
>索引</a></li>
|
||
<li class="right" >
|
||
<a href="../py-modindex.html" title="Python 模块索引"
|
||
>模块</a> |</li>
|
||
<li class="right" >
|
||
<a href="import.html" title="导入模块"
|
||
>下一页</a> |</li>
|
||
<li class="right" >
|
||
<a href="utilities.html" title="工具"
|
||
>上一页</a> |</li>
|
||
|
||
<li><img src="../_static/py.svg" alt="python logo" style="vertical-align: middle; margin-top: -1px"/></li>
|
||
<li><a href="https://www.python.org/">Python</a> »</li>
|
||
<li class="switchers">
|
||
<div class="language_switcher_placeholder"></div>
|
||
<div class="version_switcher_placeholder"></div>
|
||
</li>
|
||
<li>
|
||
|
||
</li>
|
||
<li id="cpython-language-and-version">
|
||
<a href="../index.html">3.8.20 Documentation</a> »
|
||
</li>
|
||
|
||
<li class="nav-item nav-item-1"><a href="index.html" >Python/C API 参考手册</a> »</li>
|
||
<li class="nav-item nav-item-2"><a href="utilities.html" >工具</a> »</li>
|
||
<li class="right">
|
||
|
||
|
||
<div class="inline-search" role="search">
|
||
<form class="inline-search" action="../search.html" method="get">
|
||
<input placeholder="快速搜索" aria-label="快速搜索" type="text" name="q" />
|
||
<input type="submit" value="转向" />
|
||
<input type="hidden" name="check_keywords" value="yes" />
|
||
<input type="hidden" name="area" value="default" />
|
||
</form>
|
||
</div>
|
||
|
|
||
</li>
|
||
|
||
</ul>
|
||
</div>
|
||
<div class="footer">
|
||
© <a href="../copyright.html">版权所有</a> 2001-2024, Python Software Foundation.
|
||
<br />
|
||
This page is licensed under the Python Software Foundation License Version 2.
|
||
<br />
|
||
Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
|
||
<br />
|
||
|
||
<br />
|
||
|
||
The Python Software Foundation is a non-profit corporation.
|
||
<a href="https://www.python.org/psf/donations/">Please donate.</a>
|
||
<br />
|
||
<br />
|
||
|
||
最后更新于 12月 09, 2024.
|
||
<a href="https://docs.python.org/3/bugs.html">Found a bug</a>?
|
||
<br />
|
||
|
||
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 2.4.4.
|
||
</div>
|
||
|
||
</body>
|
||
</html> |