| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
| 2 | <html> |
| 3 | <head> |
| 4 | <link rel="STYLESHEET" href="api.css" type='text/css' /> |
| 5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> |
| 6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> |
| 7 | <link rel="first" href="api.html" title='Python/C API Reference Manual' /> |
| 8 | <link rel='contents' href='contents.html' title="Contents" /> |
| 9 | <link rel='index' href='genindex.html' title='Index' /> |
| 10 | <link rel='last' href='about.html' title='About this document...' /> |
| 11 | <link rel='help' href='about.html' title='About this document...' /> |
| 12 | <link rel="next" href="memory.html" /> |
| 13 | <link rel="prev" href="concrete.html" /> |
| 14 | <link rel="parent" href="api.html" /> |
| 15 | <link rel="next" href="threads.html" /> |
| 16 | <meta name='aesop' content='information' /> |
| 17 | <title>8. Initialization, Finalization, and Threads </title> |
| 18 | </head> |
| 19 | <body> |
| 20 | <DIV CLASS="navigation"> |
| 21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> |
| 22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 23 | <tr> |
| 24 | <td class='online-navigation'><a rel="prev" title="7.5.12 DateTime Objects" |
| 25 | href="datetime-objects.html"><img src='../icons/previous.png' |
| 26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 27 | <td class='online-navigation'><a rel="parent" title="Python/C API Reference Manual" |
| 28 | href="api.html"><img src='../icons/up.png' |
| 29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 30 | <td class='online-navigation'><a rel="next" title="8.1 Thread State and" |
| 31 | href="threads.html"><img src='../icons/next.png' |
| 32 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 33 | <td align="center" width="100%">Python/C API Reference Manual</td> |
| 34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 35 | href="contents.html"><img src='../icons/contents.png' |
| 36 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 37 | <td class='online-navigation'><img src='../icons/blank.png' |
| 38 | border='0' height='32' alt='' width='32' /></td> |
| 39 | <td class='online-navigation'><a rel="index" title="Index" |
| 40 | href="genindex.html"><img src='../icons/index.png' |
| 41 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 42 | </tr></table> |
| 43 | <div class='online-navigation'> |
| 44 | <b class="navlabel">Previous:</b> |
| 45 | <a class="sectref" rel="prev" href="datetime-objects.html">7.5.12 DateTime Objects</A> |
| 46 | <b class="navlabel">Up:</b> |
| 47 | <a class="sectref" rel="parent" href="api.html">Python/C API Reference Manual</A> |
| 48 | <b class="navlabel">Next:</b> |
| 49 | <a class="sectref" rel="next" href="threads.html">8.1 Thread State and</A> |
| 50 | </div> |
| 51 | <hr /></div> |
| 52 | </DIV> |
| 53 | <!--End of Navigation Panel--> |
| 54 | |
| 55 | <H1><A NAME="SECTION0010000000000000000000"></A><A NAME="initialization"></A> |
| 56 | <BR> |
| 57 | 8. Initialization, Finalization, and Threads |
| 58 | |
| 59 | </H1> |
| 60 | |
| 61 | <P> |
| 62 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>void <b><tt id='l2h-773' xml:id='l2h-773' class="cfunction">Py_Initialize</tt></b>(</nobr></td><td>)</td></tr></table></dt> |
| 63 | <dd> |
| 64 | Initialize the Python interpreter. In an application embedding |
| 65 | Python, this should be called before using any other Python/C API |
| 66 | functions; with the exception of |
| 67 | <tt class="cfunction">Py_SetProgramName()</tt><a id='l2h-815' xml:id='l2h-815'></a>, |
| 68 | <tt class="cfunction">PyEval_InitThreads()</tt><a id='l2h-816' xml:id='l2h-816'></a>, |
| 69 | <tt class="cfunction">PyEval_ReleaseLock()</tt><a id='l2h-817' xml:id='l2h-817'></a>, |
| 70 | and <tt class="cfunction">PyEval_AcquireLock()</tt><a id='l2h-818' xml:id='l2h-818'></a>. |
| 71 | This initializes the table of loaded modules (<code>sys.modules</code>), |
| 72 | and<a id='l2h-775' xml:id='l2h-775'></a> creates the fundamental modules |
| 73 | <tt class="module">__builtin__</tt><a id='l2h-819' xml:id='l2h-819'></a>, |
| 74 | <tt class="module">__main__</tt><a id='l2h-820' xml:id='l2h-820'></a> and |
| 75 | <tt class="module">sys</tt><a id='l2h-821' xml:id='l2h-821'></a>. It also initializes the module |
| 76 | search<a id='l2h-776' xml:id='l2h-776'></a> path (<code>sys.path</code>). |
| 77 | It does not set <code>sys.argv</code>; use |
| 78 | <tt class="cfunction">PySys_SetArgv()</tt><a id='l2h-822' xml:id='l2h-822'></a> for that. This |
| 79 | is a no-op when called for a second time (without calling |
| 80 | <tt class="cfunction">Py_Finalize()</tt><a id='l2h-823' xml:id='l2h-823'></a> first). There is |
| 81 | no return value; it is a fatal error if the initialization fails. |
| 82 | </dd></dl> |
| 83 | |
| 84 | <P> |
| 85 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>void <b><tt id='l2h-777' xml:id='l2h-777' class="cfunction">Py_InitializeEx</tt></b>(</nobr></td><td>int <var>initsigs</var>)</td></tr></table></dt> |
| 86 | <dd> |
| 87 | This function works like <tt class="cfunction">Py_Initialize()</tt> if |
| 88 | <var>initsigs</var> is 1. If <var>initsigs</var> is 0, it skips |
| 89 | initialization registration of signal handlers, which |
| 90 | might be useful when Python is embedded. |
| 91 | <span class="versionnote">New in version 2.4.</span> |
| 92 | |
| 93 | </dd></dl> |
| 94 | |
| 95 | <P> |
| 96 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-778' xml:id='l2h-778' class="cfunction">Py_IsInitialized</tt></b>(</nobr></td><td>)</td></tr></table></dt> |
| 97 | <dd> |
| 98 | Return true (nonzero) when the Python interpreter has been |
| 99 | initialized, false (zero) if not. After <tt class="cfunction">Py_Finalize()</tt> |
| 100 | is called, this returns false until <tt class="cfunction">Py_Initialize()</tt> is |
| 101 | called again. |
| 102 | </dd></dl> |
| 103 | |
| 104 | <P> |
| 105 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>void <b><tt id='l2h-779' xml:id='l2h-779' class="cfunction">Py_Finalize</tt></b>(</nobr></td><td>)</td></tr></table></dt> |
| 106 | <dd> |
| 107 | Undo all initializations made by <tt class="cfunction">Py_Initialize()</tt> and |
| 108 | subsequent use of Python/C API functions, and destroy all |
| 109 | sub-interpreters (see <tt class="cfunction">Py_NewInterpreter()</tt> below) that |
| 110 | were created and not yet destroyed since the last call to |
| 111 | <tt class="cfunction">Py_Initialize()</tt>. Ideally, this frees all memory |
| 112 | allocated by the Python interpreter. This is a no-op when called |
| 113 | for a second time (without calling <tt class="cfunction">Py_Initialize()</tt> again |
| 114 | first). There is no return value; errors during finalization are |
| 115 | ignored. |
| 116 | |
| 117 | <P> |
| 118 | This function is provided for a number of reasons. An embedding |
| 119 | application might want to restart Python without having to restart |
| 120 | the application itself. An application that has loaded the Python |
| 121 | interpreter from a dynamically loadable library (or DLL) might want |
| 122 | to free all memory allocated by Python before unloading the |
| 123 | DLL. During a hunt for memory leaks in an application a developer |
| 124 | might want to free all memory allocated by Python before exiting |
| 125 | from the application. |
| 126 | |
| 127 | <P> |
| 128 | <strong>Bugs and caveats:</strong> The destruction of modules and objects in |
| 129 | modules is done in random order; this may cause destructors |
| 130 | (<tt class="method">__del__()</tt> methods) to fail when they depend on other |
| 131 | objects (even functions) or modules. Dynamically loaded extension |
| 132 | modules loaded by Python are not unloaded. Small amounts of memory |
| 133 | allocated by the Python interpreter may not be freed (if you find a |
| 134 | leak, please report it). Memory tied up in circular references |
| 135 | between objects is not freed. Some memory allocated by extension |
| 136 | modules may not be freed. Some extensions may not work properly if |
| 137 | their initialization routine is called more than once; this can |
| 138 | happen if an application calls <tt class="cfunction">Py_Initialize()</tt> and |
| 139 | <tt class="cfunction">Py_Finalize()</tt> more than once. |
| 140 | </dd></dl> |
| 141 | |
| 142 | <P> |
| 143 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyThreadState* <b><tt id='l2h-780' xml:id='l2h-780' class="cfunction">Py_NewInterpreter</tt></b>(</nobr></td><td>)</td></tr></table></dt> |
| 144 | <dd> |
| 145 | Create a new sub-interpreter. This is an (almost) totally separate |
| 146 | environment for the execution of Python code. In particular, the |
| 147 | new interpreter has separate, independent versions of all imported |
| 148 | modules, including the fundamental modules |
| 149 | <tt class="module">__builtin__</tt><a id='l2h-824' xml:id='l2h-824'></a>, |
| 150 | <tt class="module">__main__</tt><a id='l2h-825' xml:id='l2h-825'></a> and |
| 151 | <tt class="module">sys</tt><a id='l2h-826' xml:id='l2h-826'></a>. The table of loaded modules |
| 152 | (<code>sys.modules</code>) and the module search path (<code>sys.path</code>) |
| 153 | are also separate. The new environment has no <code>sys.argv</code> |
| 154 | variable. It has new standard I/O stream file objects |
| 155 | <code>sys.stdin</code>, <code>sys.stdout</code> and <code>sys.stderr</code> (however |
| 156 | these refer to the same underlying <tt class="ctype">FILE</tt> structures in the C |
| 157 | library). |
| 158 | <a id='l2h-782' xml:id='l2h-782'></a> |
| 159 | <P> |
| 160 | The return value points to the first thread state created in the new |
| 161 | sub-interpreter. This thread state is made in the current thread |
| 162 | state. Note that no actual thread is created; see the discussion of |
| 163 | thread states below. If creation of the new interpreter is |
| 164 | unsuccessful, <tt class="constant">NULL</tt> is returned; no exception is set since the |
| 165 | exception state is stored in the current thread state and there may |
| 166 | not be a current thread state. (Like all other Python/C API |
| 167 | functions, the global interpreter lock must be held before calling |
| 168 | this function and is still held when it returns; however, unlike |
| 169 | most other Python/C API functions, there needn't be a current thread |
| 170 | state on entry.) |
| 171 | |
| 172 | <P> |
| 173 | Extension modules are shared between (sub-)interpreters as follows: |
| 174 | the first time a particular extension is imported, it is initialized |
| 175 | normally, and a (shallow) copy of its module's dictionary is |
| 176 | squirreled away. When the same extension is imported by another |
| 177 | (sub-)interpreter, a new module is initialized and filled with the |
| 178 | contents of this copy; the extension's <code>init</code> function is not |
| 179 | called. Note that this is different from what happens when an |
| 180 | extension is imported after the interpreter has been completely |
| 181 | re-initialized by calling |
| 182 | <tt class="cfunction">Py_Finalize()</tt><a id='l2h-827' xml:id='l2h-827'></a> and |
| 183 | <tt class="cfunction">Py_Initialize()</tt><a id='l2h-828' xml:id='l2h-828'></a>; in that case, |
| 184 | the extension's <code>init<var>module</var></code> function <em>is</em> called |
| 185 | again. |
| 186 | |
| 187 | <P> |
| 188 | <strong>Bugs and caveats:</strong> Because sub-interpreters (and the main |
| 189 | interpreter) are part of the same process, the insulation between |
| 190 | them isn't perfect -- for example, using low-level file operations |
| 191 | like <a id='l2h-784' xml:id='l2h-784'></a> <tt class="function">os.close()</tt> they can (accidentally or maliciously) affect |
| 192 | each other's open files. Because of the way extensions are shared |
| 193 | between (sub-)interpreters, some extensions may not work properly; |
| 194 | this is especially likely when the extension makes use of (static) |
| 195 | global variables, or when the extension manipulates its module's |
| 196 | dictionary after its initialization. It is possible to insert |
| 197 | objects created in one sub-interpreter into a namespace of another |
| 198 | sub-interpreter; this should be done with great care to avoid |
| 199 | sharing user-defined functions, methods, instances or classes |
| 200 | between sub-interpreters, since import operations executed by such |
| 201 | objects may affect the wrong (sub-)interpreter's dictionary of |
| 202 | loaded modules. (XXX This is a hard-to-fix bug that will be |
| 203 | addressed in a future release.) |
| 204 | </dd></dl> |
| 205 | |
| 206 | <P> |
| 207 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>void <b><tt id='l2h-785' xml:id='l2h-785' class="cfunction">Py_EndInterpreter</tt></b>(</nobr></td><td>PyThreadState *<var>tstate</var>)</td></tr></table></dt> |
| 208 | <dd> |
| 209 | Destroy the (sub-)interpreter represented by the given thread state. |
| 210 | The given thread state must be the current thread state. See the |
| 211 | discussion of thread states below. When the call returns, the |
| 212 | current thread state is <tt class="constant">NULL</tt>. All thread states associated with |
| 213 | this interpreter are destroyed. (The global interpreter lock must |
| 214 | be held before calling this function and is still held when it |
| 215 | returns.) <tt class="cfunction">Py_Finalize()</tt><a id='l2h-829' xml:id='l2h-829'></a> will |
| 216 | destroy all sub-interpreters that haven't been explicitly destroyed |
| 217 | at that point. |
| 218 | </dd></dl> |
| 219 | |
| 220 | <P> |
| 221 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>void <b><tt id='l2h-786' xml:id='l2h-786' class="cfunction">Py_SetProgramName</tt></b>(</nobr></td><td>char *<var>name</var>)</td></tr></table></dt> |
| 222 | <dd> |
| 223 | This function should be called before |
| 224 | <tt class="cfunction">Py_Initialize()</tt><a id='l2h-830' xml:id='l2h-830'></a> is called |
| 225 | for the first time, if it is called at all. It tells the |
| 226 | interpreter the value of the <code>argv[0]</code> argument to the |
| 227 | <tt class="cfunction">main()</tt><a id='l2h-831' xml:id='l2h-831'></a> function of the program. This is |
| 228 | used by <tt class="cfunction">Py_GetPath()</tt><a id='l2h-832' xml:id='l2h-832'></a> and some |
| 229 | other functions below to find the Python run-time libraries relative |
| 230 | to the interpreter executable. The default value is |
| 231 | <code>'python'</code>. The argument should point to a zero-terminated |
| 232 | character string in static storage whose contents will not change |
| 233 | for the duration of the program's execution. No code in the Python |
| 234 | interpreter will change the contents of this storage. |
| 235 | </dd></dl> |
| 236 | |
| 237 | <P> |
| 238 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>char* <b><tt id='l2h-787' xml:id='l2h-787' class="cfunction">Py_GetProgramName</tt></b>(</nobr></td><td>)</td></tr></table></dt> |
| 239 | <dd> |
| 240 | Return the program name set with |
| 241 | <tt class="cfunction">Py_SetProgramName()</tt><a id='l2h-833' xml:id='l2h-833'></a>, or the |
| 242 | default. The returned string points into static storage; the caller |
| 243 | should not modify its value. |
| 244 | </dd></dl> |
| 245 | |
| 246 | <P> |
| 247 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>char* <b><tt id='l2h-788' xml:id='l2h-788' class="cfunction">Py_GetPrefix</tt></b>(</nobr></td><td>)</td></tr></table></dt> |
| 248 | <dd> |
| 249 | Return the <em>prefix</em> for installed platform-independent files. |
| 250 | This is derived through a number of complicated rules from the |
| 251 | program name set with <tt class="cfunction">Py_SetProgramName()</tt> and some |
| 252 | environment variables; for example, if the program name is |
| 253 | <code>'/usr/local/bin/python'</code>, the prefix is <code>'/usr/local'</code>. |
| 254 | The returned string points into static storage; the caller should |
| 255 | not modify its value. This corresponds to the <span class="makevar">prefix</span> |
| 256 | variable in the top-level <span class="file">Makefile</span> and the |
| 257 | <b class="programopt">--prefix</b> argument to the <b class="program">configure</b> script |
| 258 | at build time. The value is available to Python code as |
| 259 | <code>sys.prefix</code>. It is only useful on <span class="Unix">Unix</span>. See also the next |
| 260 | function. |
| 261 | </dd></dl> |
| 262 | |
| 263 | <P> |
| 264 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>char* <b><tt id='l2h-789' xml:id='l2h-789' class="cfunction">Py_GetExecPrefix</tt></b>(</nobr></td><td>)</td></tr></table></dt> |
| 265 | <dd> |
| 266 | Return the <em>exec-prefix</em> for installed |
| 267 | platform-<em>de</em>pendent files. This is derived through a number |
| 268 | of complicated rules from the program name set with |
| 269 | <tt class="cfunction">Py_SetProgramName()</tt> and some environment variables; for |
| 270 | example, if the program name is <code>'/usr/local/bin/python'</code>, the |
| 271 | exec-prefix is <code>'/usr/local'</code>. The returned string points into |
| 272 | static storage; the caller should not modify its value. This |
| 273 | corresponds to the <span class="makevar">exec_prefix</span> variable in the top-level |
| 274 | <span class="file">Makefile</span> and the <b class="programopt">--exec-prefix</b> argument to the |
| 275 | <b class="program">configure</b> script at build time. The value is available |
| 276 | to Python code as <code>sys.exec_prefix</code>. It is only useful on |
| 277 | <span class="Unix">Unix</span>. |
| 278 | |
| 279 | <P> |
| 280 | Background: The exec-prefix differs from the prefix when platform |
| 281 | dependent files (such as executables and shared libraries) are |
| 282 | installed in a different directory tree. In a typical installation, |
| 283 | platform dependent files may be installed in the |
| 284 | <span class="file">/usr/local/plat</span> subtree while platform independent may be |
| 285 | installed in <span class="file">/usr/local</span>. |
| 286 | |
| 287 | <P> |
| 288 | Generally speaking, a platform is a combination of hardware and |
| 289 | software families, e.g. Sparc machines running the Solaris 2.x |
| 290 | operating system are considered the same platform, but Intel |
| 291 | machines running Solaris 2.x are another platform, and Intel |
| 292 | machines running Linux are yet another platform. Different major |
| 293 | revisions of the same operating system generally also form different |
| 294 | platforms. Non-<span class="Unix">Unix</span> operating systems are a different story; the |
| 295 | installation strategies on those systems are so different that the |
| 296 | prefix and exec-prefix are meaningless, and set to the empty string. |
| 297 | Note that compiled Python bytecode files are platform independent |
| 298 | (but not independent from the Python version by which they were |
| 299 | compiled!). |
| 300 | |
| 301 | <P> |
| 302 | System administrators will know how to configure the <b class="program">mount</b> |
| 303 | or <b class="program">automount</b> programs to share <span class="file">/usr/local</span> between |
| 304 | platforms while having <span class="file">/usr/local/plat</span> be a different |
| 305 | filesystem for each platform. |
| 306 | </dd></dl> |
| 307 | |
| 308 | <P> |
| 309 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>char* <b><tt id='l2h-790' xml:id='l2h-790' class="cfunction">Py_GetProgramFullPath</tt></b>(</nobr></td><td>)</td></tr></table></dt> |
| 310 | <dd> |
| 311 | Return the full program name of the Python executable; this is |
| 312 | computed as a side-effect of deriving the default module search path |
| 313 | from the program name (set by |
| 314 | <tt class="cfunction">Py_SetProgramName()</tt><a id='l2h-834' xml:id='l2h-834'></a> above). |
| 315 | The returned string points into static storage; the caller should |
| 316 | not modify its value. The value is available to Python code as |
| 317 | <code>sys.executable</code>. |
| 318 | <a id='l2h-792' xml:id='l2h-792'></a></dd></dl> |
| 319 | |
| 320 | <P> |
| 321 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>char* <b><tt id='l2h-793' xml:id='l2h-793' class="cfunction">Py_GetPath</tt></b>(</nobr></td><td>)</td></tr></table></dt> |
| 322 | <dd> |
| 323 | <a id='l2h-794' xml:id='l2h-794'></a> Return the default module search path; this is computed from the |
| 324 | program name (set by <tt class="cfunction">Py_SetProgramName()</tt> above) and some |
| 325 | environment variables. The returned string consists of a series of |
| 326 | directory names separated by a platform dependent delimiter |
| 327 | character. The delimiter character is "<tt class="character">:</tt>" on <span class="Unix">Unix</span>and Mac OS X, |
| 328 | "<tt class="character">;</tt>" on Windows. The returned string points into |
| 329 | static storage; the caller should not modify its value. The value |
| 330 | is available to Python code as the list |
| 331 | <code>sys.path</code><a id='l2h-796' xml:id='l2h-796'></a>, which |
| 332 | may be modified to change the future search path for loaded |
| 333 | modules. |
| 334 | |
| 335 | <P> |
| 336 | </dd></dl> |
| 337 | |
| 338 | <P> |
| 339 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>const char* <b><tt id='l2h-797' xml:id='l2h-797' class="cfunction">Py_GetVersion</tt></b>(</nobr></td><td>)</td></tr></table></dt> |
| 340 | <dd> |
| 341 | Return the version of this Python interpreter. This is a string |
| 342 | that looks something like |
| 343 | |
| 344 | <P> |
| 345 | <div class="verbatim"><pre> |
| 346 | "1.5 (#67, Dec 31 1997, 22:34:28) [GCC 2.7.2.2]" |
| 347 | </pre></div> |
| 348 | |
| 349 | <P> |
| 350 | The first word (up to the first space character) is the current |
| 351 | Python version; the first three characters are the major and minor |
| 352 | version separated by a period. The returned string points into |
| 353 | static storage; the caller should not modify its value. The value |
| 354 | is available to Python code as <code>sys.version</code>. |
| 355 | <a id='l2h-799' xml:id='l2h-799'></a></dd></dl> |
| 356 | |
| 357 | <P> |
| 358 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>const char* <b><tt id='l2h-800' xml:id='l2h-800' class="cfunction">Py_GetPlatform</tt></b>(</nobr></td><td>)</td></tr></table></dt> |
| 359 | <dd> |
| 360 | Return the platform identifier for the current platform. On <span class="Unix">Unix</span>, |
| 361 | this is formed from the ``official'' name of the operating system, |
| 362 | converted to lower case, followed by the major revision number; |
| 363 | e.g., for Solaris 2.x, which is also known as SunOS 5.x, the value |
| 364 | is <code>'sunos5'</code>. On Mac OS X, it is <code>'darwin'</code>. On Windows, |
| 365 | it is <code>'win'</code>. The returned string points into static storage; |
| 366 | the caller should not modify its value. The value is available to |
| 367 | Python code as <code>sys.platform</code>. |
| 368 | <a id='l2h-802' xml:id='l2h-802'></a></dd></dl> |
| 369 | |
| 370 | <P> |
| 371 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>const char* <b><tt id='l2h-803' xml:id='l2h-803' class="cfunction">Py_GetCopyright</tt></b>(</nobr></td><td>)</td></tr></table></dt> |
| 372 | <dd> |
| 373 | Return the official copyright string for the current Python version, |
| 374 | for example |
| 375 | |
| 376 | <P> |
| 377 | <code>'Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam'</code> |
| 378 | |
| 379 | <P> |
| 380 | The returned string points into static storage; the caller should |
| 381 | not modify its value. The value is available to Python code as |
| 382 | <code>sys.copyright</code>. |
| 383 | <a id='l2h-805' xml:id='l2h-805'></a></dd></dl> |
| 384 | |
| 385 | <P> |
| 386 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>const char* <b><tt id='l2h-806' xml:id='l2h-806' class="cfunction">Py_GetCompiler</tt></b>(</nobr></td><td>)</td></tr></table></dt> |
| 387 | <dd> |
| 388 | Return an indication of the compiler used to build the current |
| 389 | Python version, in square brackets, for example: |
| 390 | |
| 391 | <P> |
| 392 | <div class="verbatim"><pre> |
| 393 | "[GCC 2.7.2.2]" |
| 394 | </pre></div> |
| 395 | |
| 396 | <P> |
| 397 | The returned string points into static storage; the caller should |
| 398 | not modify its value. The value is available to Python code as part |
| 399 | of the variable <code>sys.version</code>. |
| 400 | <a id='l2h-808' xml:id='l2h-808'></a></dd></dl> |
| 401 | |
| 402 | <P> |
| 403 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>const char* <b><tt id='l2h-809' xml:id='l2h-809' class="cfunction">Py_GetBuildInfo</tt></b>(</nobr></td><td>)</td></tr></table></dt> |
| 404 | <dd> |
| 405 | Return information about the sequence number and build date and time |
| 406 | of the current Python interpreter instance, for example |
| 407 | |
| 408 | <P> |
| 409 | <div class="verbatim"><pre> |
| 410 | "#67, Aug 1 1997, 22:34:28" |
| 411 | </pre></div> |
| 412 | |
| 413 | <P> |
| 414 | The returned string points into static storage; the caller should |
| 415 | not modify its value. The value is available to Python code as part |
| 416 | of the variable <code>sys.version</code>. |
| 417 | <a id='l2h-811' xml:id='l2h-811'></a></dd></dl> |
| 418 | |
| 419 | <P> |
| 420 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-812' xml:id='l2h-812' class="cfunction">PySys_SetArgv</tt></b>(</nobr></td><td>int <var>argc</var>, char **<var>argv</var>)</td></tr></table></dt> |
| 421 | <dd> |
| 422 | Set <code>sys.argv</code> based on <var>argc</var> and <var>argv</var>. These |
| 423 | parameters are similar to those passed to the program's |
| 424 | <tt class="cfunction">main()</tt><a id='l2h-835' xml:id='l2h-835'></a> function with the difference that |
| 425 | the first entry should refer to the script file to be executed |
| 426 | rather than the executable hosting the Python interpreter. If there |
| 427 | isn't a script that will be run, the first entry in <var>argv</var> can |
| 428 | be an empty string. If this function fails to initialize |
| 429 | <code>sys.argv</code>, a fatal condition is signalled using |
| 430 | <tt class="cfunction">Py_FatalError()</tt><a id='l2h-836' xml:id='l2h-836'></a>. |
| 431 | <a id='l2h-814' xml:id='l2h-814'></a> </dd></dl> |
| 432 | |
| 433 | <P> |
| 434 | |
| 435 | <p><br /></p><hr class='online-navigation' /> |
| 436 | <div class='online-navigation'> |
| 437 | <!--Table of Child-Links--> |
| 438 | <A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></a> |
| 439 | |
| 440 | <UL CLASS="ChildLinks"> |
| 441 | <LI><A href="threads.html">8.1 Thread State and the Global Interpreter Lock</a> |
| 442 | <LI><A href="profiling.html">8.2 Profiling and Tracing</a> |
| 443 | <LI><A href="advanced-debugging.html">8.3 Advanced Debugger Support</a> |
| 444 | </ul> |
| 445 | <!--End of Table of Child-Links--> |
| 446 | </div> |
| 447 | |
| 448 | <DIV CLASS="navigation"> |
| 449 | <div class='online-navigation'> |
| 450 | <p></p><hr /> |
| 451 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 452 | <tr> |
| 453 | <td class='online-navigation'><a rel="prev" title="7.5.12 DateTime Objects" |
| 454 | href="datetime-objects.html"><img src='../icons/previous.png' |
| 455 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 456 | <td class='online-navigation'><a rel="parent" title="Python/C API Reference Manual" |
| 457 | href="api.html"><img src='../icons/up.png' |
| 458 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 459 | <td class='online-navigation'><a rel="next" title="8.1 Thread State and" |
| 460 | href="threads.html"><img src='../icons/next.png' |
| 461 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 462 | <td align="center" width="100%">Python/C API Reference Manual</td> |
| 463 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 464 | href="contents.html"><img src='../icons/contents.png' |
| 465 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 466 | <td class='online-navigation'><img src='../icons/blank.png' |
| 467 | border='0' height='32' alt='' width='32' /></td> |
| 468 | <td class='online-navigation'><a rel="index" title="Index" |
| 469 | href="genindex.html"><img src='../icons/index.png' |
| 470 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 471 | </tr></table> |
| 472 | <div class='online-navigation'> |
| 473 | <b class="navlabel">Previous:</b> |
| 474 | <a class="sectref" rel="prev" href="datetime-objects.html">7.5.12 DateTime Objects</A> |
| 475 | <b class="navlabel">Up:</b> |
| 476 | <a class="sectref" rel="parent" href="api.html">Python/C API Reference Manual</A> |
| 477 | <b class="navlabel">Next:</b> |
| 478 | <a class="sectref" rel="next" href="threads.html">8.1 Thread State and</A> |
| 479 | </div> |
| 480 | </div> |
| 481 | <hr /> |
| 482 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> |
| 483 | </DIV> |
| 484 | <!--End of Navigation Panel--> |
| 485 | <ADDRESS> |
| 486 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. |
| 487 | </ADDRESS> |
| 488 | </BODY> |
| 489 | </HTML> |