blob: 3f8f7b6a777de18de9b08e3aefbf8d7996e9ea81 [file] [log] [blame]
Fred Drake295da241998-08-10 19:42:37 +00001\section{\module{sys} ---
Fred Drakeffbe6871999-04-22 21:23:22 +00002 System-specific parameters and functions}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00003
Fred Drakeffbe6871999-04-22 21:23:22 +00004\declaremodule{builtin}{sys}
Fred Drake295da241998-08-10 19:42:37 +00005\modulesynopsis{Access system-specific parameters and functions.}
Fred Drakeb91e9341998-07-23 17:59:49 +00006
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00007This module provides access to some variables used or maintained by the
8interpreter and to functions that interact strongly with the interpreter.
9It is always available.
10
Guido van Rossum470be141995-03-17 16:07:09 +000011
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000012\begin{datadesc}{argv}
13 The list of command line arguments passed to a Python script.
Fred Drake72182022001-07-18 17:52:58 +000014 \code{argv[0]} is the script name (it is operating system dependent
15 whether this is a full pathname or not). If the command was
16 executed using the \programopt{-c} command line option to the
17 interpreter, \code{argv[0]} is set to the string \code{'-c'}. If no
18 script name was passed to the Python interpreter, \code{argv} has
19 zero length.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000020\end{datadesc}
21
Fred Drakea2b6ad62000-08-15 04:24:43 +000022\begin{datadesc}{byteorder}
Fred Drake68e29152000-08-14 15:47:30 +000023 An indicator of the native byte order. This will have the value
24 \code{'big'} on big-endian (most-signigicant byte first) platforms,
25 and \code{'little'} on little-endian (least-significant byte first)
26 platforms.
27 \versionadded{2.0}
28\end{datadesc}
29
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000030\begin{datadesc}{builtin_module_names}
Guido van Rossum0d2971b1997-01-06 23:01:02 +000031 A tuple of strings giving the names of all modules that are compiled
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000032 into this Python interpreter. (This information is not available in
Fred Drake0fd72ee1998-03-08 05:43:51 +000033 any other way --- \code{modules.keys()} only lists the imported
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000034 modules.)
35\end{datadesc}
36
Guido van Rossum3e5fe421998-06-10 17:57:44 +000037\begin{datadesc}{copyright}
Fred Drake72182022001-07-18 17:52:58 +000038 A string containing the copyright pertaining to the Python
39 interpreter.
Guido van Rossum3e5fe421998-06-10 17:57:44 +000040\end{datadesc}
41
Fred Drake38e5d272000-04-03 20:13:55 +000042\begin{datadesc}{dllhandle}
Fred Drake72182022001-07-18 17:52:58 +000043 Integer specifying the handle of the Python DLL.
44 Availability: Windows.
Fred Drake38e5d272000-04-03 20:13:55 +000045\end{datadesc}
46
Moshe Zadkaf68f2fe2001-01-11 05:41:27 +000047\begin{funcdesc}{displayhook}{\var{value}}
Fred Drake72182022001-07-18 17:52:58 +000048 If \var{value} is not \code{None}, this function prints it to
49 \code{sys.stdout}, and saves it in \code{__builtin__._}.
Moshe Zadkaf68f2fe2001-01-11 05:41:27 +000050
Fred Drake72182022001-07-18 17:52:58 +000051 \code{sys.displayhook} is called on the result of evaluating an
52 expression entered in an interactive Python session. The display of
53 these values can be customized by assigning another one-argument
54 function to \code{sys.displayhook}.
Moshe Zadkaf68f2fe2001-01-11 05:41:27 +000055\end{funcdesc}
56
Ka-Ping Yeeb5c51322001-03-23 02:46:52 +000057\begin{funcdesc}{excepthook}{\var{type}, \var{value}, \var{traceback}}
Fred Drake72182022001-07-18 17:52:58 +000058 This function prints out a given traceback and exception to
59 \code{sys.stderr}.
Ka-Ping Yeeb5c51322001-03-23 02:46:52 +000060
Fred Drake72182022001-07-18 17:52:58 +000061 When an exception is raised and uncaught, the interpreter calls
62 \code{sys.excepthook} with three arguments, the exception class,
63 exception instance, and a traceback object. In an interactive
64 session this happens just before control is returned to the prompt;
65 in a Python program this happens just before the program exits. The
66 handling of such top-level exceptions can be customized by assigning
67 another three-argument function to \code{sys.excepthook}.
Ka-Ping Yeeb5c51322001-03-23 02:46:52 +000068\end{funcdesc}
69
70\begin{datadesc}{__displayhook__}
71\dataline{__excepthook__}
Fred Drake72182022001-07-18 17:52:58 +000072 These objects contain the original values of \code{displayhook} and
73 \code{excepthook} at the start of the program. They are saved so
74 that \code{displayhook} and \code{excepthook} can be restored in
75 case they happen to get replaced with broken objects.
Ka-Ping Yeeb5c51322001-03-23 02:46:52 +000076\end{datadesc}
77
Guido van Rossum871cf161997-10-20 22:38:43 +000078\begin{funcdesc}{exc_info}{}
Fred Drake72182022001-07-18 17:52:58 +000079 This function returns a tuple of three values that give information
80 about the exception that is currently being handled. The
81 information returned is specific both to the current thread and to
82 the current stack frame. If the current stack frame is not handling
83 an exception, the information is taken from the calling stack frame,
84 or its caller, and so on until a stack frame is found that is
85 handling an exception. Here, ``handling an exception'' is defined
86 as ``executing or having executed an except clause.'' For any stack
87 frame, only information about the most recently handled exception is
88 accessible.
Guido van Rossum871cf161997-10-20 22:38:43 +000089
Fred Drake72182022001-07-18 17:52:58 +000090 If no exception is being handled anywhere on the stack, a tuple
91 containing three \code{None} values is returned. Otherwise, the
92 values returned are \code{(\var{type}, \var{value},
93 \var{traceback})}. Their meaning is: \var{type} gets the exception
94 type of the exception being handled (a string or class object);
95 \var{value} gets the exception parameter (its \dfn{associated value}
96 or the second argument to \keyword{raise}, which is always a class
97 instance if the exception type is a class object); \var{traceback}
98 gets a traceback object (see the Reference Manual) which
99 encapsulates the call stack at the point where the exception
100 originally occurred. \obindex{traceback}
Guido van Rossum871cf161997-10-20 22:38:43 +0000101
Fred Drake0aa811c2001-10-20 04:24:09 +0000102 \warning{Assigning the \var{traceback} return value to a
Fred Drake72182022001-07-18 17:52:58 +0000103 local variable in a function that is handling an exception will
104 cause a circular reference. This will prevent anything referenced
105 by a local variable in the same function or by the traceback from
106 being garbage collected. Since most functions don't need access to
107 the traceback, the best solution is to use something like
Fred Drake7731ed42002-01-05 04:00:03 +0000108 \code{exctype, value = sys.exc_info()[:2]} to extract only the
Fred Drake72182022001-07-18 17:52:58 +0000109 exception type and value. If you do need the traceback, make sure
110 to delete it after use (best done with a \keyword{try}
111 ... \keyword{finally} statement) or to call \function{exc_info()} in
Tim Peters98791af2001-10-23 01:59:54 +0000112 a function that does not itself handle an exception.} \note{Beginning
113 with Python 2.2, such cycles are automatically reclaimed when garbage
114 collection is enabled and they become unreachable, but it remains more
115 efficient to avoid creating cycles.}
Guido van Rossum871cf161997-10-20 22:38:43 +0000116\end{funcdesc}
117
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000118\begin{datadesc}{exc_type}
119\dataline{exc_value}
120\dataline{exc_traceback}
Fred Drake0fd72ee1998-03-08 05:43:51 +0000121\deprecated {1.5}
122 {Use \function{exc_info()} instead.}
Fred Drake72182022001-07-18 17:52:58 +0000123 Since they are global variables, they are not specific to the
124 current thread, so their use is not safe in a multi-threaded
125 program. When no exception is being handled, \code{exc_type} is set
126 to \code{None} and the other two are undefined.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000127\end{datadesc}
128
Guido van Rossum0a3c7531997-06-02 17:32:41 +0000129\begin{datadesc}{exec_prefix}
Fred Drake72182022001-07-18 17:52:58 +0000130 A string giving the site-specific directory prefix where the
131 platform-dependent Python files are installed; by default, this is
132 also \code{'/usr/local'}. This can be set at build time with the
133 \longprogramopt{exec-prefix} argument to the \program{configure}
134 script. Specifically, all configuration files (e.g. the
Martin v. Löwis4f1cd8b2001-07-26 13:41:06 +0000135 \file{pyconfig.h} header file) are installed in the directory
Fred Drake72182022001-07-18 17:52:58 +0000136 \code{exec_prefix + '/lib/python\var{version}/config'}, and shared
137 library modules are installed in \code{exec_prefix +
138 '/lib/python\var{version}/lib-dynload'}, where \var{version} is
139 equal to \code{version[:3]}.
Guido van Rossum0a3c7531997-06-02 17:32:41 +0000140\end{datadesc}
141
Guido van Rossum3e5fe421998-06-10 17:57:44 +0000142\begin{datadesc}{executable}
Fred Drake72182022001-07-18 17:52:58 +0000143 A string giving the name of the executable binary for the Python
144 interpreter, on systems where this makes sense.
Guido van Rossum3e5fe421998-06-10 17:57:44 +0000145\end{datadesc}
146
Guido van Rossum04307ce1998-11-23 17:49:53 +0000147\begin{funcdesc}{exit}{\optional{arg}}
Fred Drake72182022001-07-18 17:52:58 +0000148 Exit from Python. This is implemented by raising the
149 \exception{SystemExit} exception, so cleanup actions specified by
150 finally clauses of \keyword{try} statements are honored, and it is
151 possible to intercept the exit attempt at an outer level. The
152 optional argument \var{arg} can be an integer giving the exit status
153 (defaulting to zero), or another type of object. If it is an
154 integer, zero is considered ``successful termination'' and any
155 nonzero value is considered ``abnormal termination'' by shells and
156 the like. Most systems require it to be in the range 0-127, and
157 produce undefined results otherwise. Some systems have a convention
158 for assigning specific meanings to specific exit codes, but these
Fred Drakec37b65e2001-11-28 07:26:15 +0000159 are generally underdeveloped; \UNIX{} programs generally use 2 for
Fred Drake72182022001-07-18 17:52:58 +0000160 command line syntax errors and 1 for all other kind of errors. If
161 another type of object is passed, \code{None} is equivalent to
162 passing zero, and any other object is printed to \code{sys.stderr}
163 and results in an exit code of 1. In particular,
164 \code{sys.exit("some error message")} is a quick way to exit a
165 program when an error occurs.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000166\end{funcdesc}
167
168\begin{datadesc}{exitfunc}
169 This value is not actually defined by the module, but can be set by
170 the user (or by a program) to specify a clean-up action at program
Fred Drake72182022001-07-18 17:52:58 +0000171 exit. When set, it should be a parameterless function. This
172 function will be called when the interpreter exits. Only one
173 function may be installed in this way; to allow multiple functions
174 which will be called at termination, use the \refmodule{atexit}
Fred Drake0aa811c2001-10-20 04:24:09 +0000175 module. \note{The exit function is not called when the program is
Fred Drake72182022001-07-18 17:52:58 +0000176 killed by a signal, when a Python fatal internal error is detected,
Fred Drake0aa811c2001-10-20 04:24:09 +0000177 or when \code{os._exit()} is called.}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000178\end{datadesc}
179
Fred Drake8940faf2000-10-25 21:02:55 +0000180\begin{funcdesc}{getdefaultencoding}{}
181 Return the name of the current default string encoding used by the
182 Unicode implementation.
183 \versionadded{2.0}
184\end{funcdesc}
185
Martin v. Löwisf0473d52001-07-18 16:17:16 +0000186\begin{funcdesc}{getdlopenflags}{}
Fred Drake5d808fb2001-07-18 16:35:05 +0000187 Return the current value of the flags that are used for
188 \cfunction{dlopen()} calls. The flag constants are defined in the
189 \refmodule{dl} and \module{DLFCN} modules.
190 Availability: \UNIX.
191 \versionadded{2.2}
Martin v. Löwisf0473d52001-07-18 16:17:16 +0000192\end{funcdesc}
193
Guido van Rossum6e91c6a1998-02-07 21:17:05 +0000194\begin{funcdesc}{getrefcount}{object}
Fred Drake72182022001-07-18 17:52:58 +0000195 Return the reference count of the \var{object}. The count returned
196 is generally one higher than you might expect, because it includes
197 the (temporary) reference as an argument to
198 \function{getrefcount()}.
Guido van Rossum6e91c6a1998-02-07 21:17:05 +0000199\end{funcdesc}
200
Jeremy Hyltonee5adfb2000-08-31 19:23:01 +0000201\begin{funcdesc}{getrecursionlimit}{}
Fred Drake72182022001-07-18 17:52:58 +0000202 Return the current value of the recursion limit, the maximum depth
203 of the Python interpreter stack. This limit prevents infinite
204 recursion from causing an overflow of the C stack and crashing
205 Python. It can be set by \function{setrecursionlimit()}.
Jeremy Hyltonee5adfb2000-08-31 19:23:01 +0000206\end{funcdesc}
207
Barry Warsawb6a54d22000-12-06 21:47:46 +0000208\begin{funcdesc}{_getframe}{\optional{depth}}
Fred Drake72182022001-07-18 17:52:58 +0000209 Return a frame object from the call stack. If optional integer
210 \var{depth} is given, return the frame object that many calls below
211 the top of the stack. If that is deeper than the call stack,
212 \exception{ValueError} is raised. The default for \var{depth} is
213 zero, returning the frame at the top of the call stack.
Barry Warsawb6a54d22000-12-06 21:47:46 +0000214
Fred Drake72182022001-07-18 17:52:58 +0000215 This function should be used for internal and specialized purposes
216 only.
Barry Warsawb6a54d22000-12-06 21:47:46 +0000217\end{funcdesc}
218
Mark Hammond8696ebc2002-10-08 02:44:31 +0000219\begin{funcdesc}{getwindowsversion}{}
220 Return a tuple containing five components, describing the Windows
221 version currently running. The elements are \var{major}, \var{minor},
222 \var{build}, \var{platform}, and \var{text}. \var{text} contains
223 a string while all other values are integers.
224
225 \var{platform} may be one of the following values:
226 \begin{list}{}{\leftmargin 0.7in \labelwidth 0.65in}
227 \item[0 (\constant{VER_PLATFORM_WIN32s})]
228 Win32s on Windows 3.1.
229 \item[1 (\constant{VER_PLATFORM_WIN32_WINDOWS})]
230 Windows 95/98/ME
231 \item[2 (\constant{VER_PLATFORM_WIN32_NT})]
232 Windows NT/2000/XP
233 \item[3 (\constant{VER_PLATFORM_WIN32_CE})]
234 Windows CE.
235 \end{list}
236
237 This function wraps the Win32 \function{GetVersionEx()} function;
238 see the Microsoft Documentation for more information about these
239 fields.
240
241 Availability: Windows.
242 \versionadded{2.3}
243\end{funcdesc}
244
Fred Drake4d65d732000-04-13 16:54:17 +0000245\begin{datadesc}{hexversion}
Fred Drake72182022001-07-18 17:52:58 +0000246 The version number encoded as a single integer. This is guaranteed
247 to increase with each version, including proper support for
248 non-production releases. For example, to test that the Python
249 interpreter is at least version 1.5.2, use:
Fred Drake4d65d732000-04-13 16:54:17 +0000250
251\begin{verbatim}
252if sys.hexversion >= 0x010502F0:
253 # use some advanced feature
254 ...
255else:
256 # use an alternative implementation or warn the user
257 ...
258\end{verbatim}
259
Fred Drake72182022001-07-18 17:52:58 +0000260 This is called \samp{hexversion} since it only really looks
261 meaningful when viewed as the result of passing it to the built-in
262 \function{hex()} function. The \code{version_info} value may be
263 used for a more human-friendly encoding of the same information.
264 \versionadded{1.5.2}
Fred Drake4d65d732000-04-13 16:54:17 +0000265\end{datadesc}
266
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000267\begin{datadesc}{last_type}
268\dataline{last_value}
269\dataline{last_traceback}
Fred Drake72182022001-07-18 17:52:58 +0000270 These three variables are not always defined; they are set when an
271 exception is not handled and the interpreter prints an error message
272 and a stack traceback. Their intended use is to allow an
273 interactive user to import a debugger module and engage in
274 post-mortem debugging without having to re-execute the command that
275 caused the error. (Typical use is \samp{import pdb; pdb.pm()} to
276 enter the post-mortem debugger; see chapter \ref{debugger}, ``The
277 Python Debugger,'' for more information.)
Guido van Rossum871cf161997-10-20 22:38:43 +0000278
Fred Drake72182022001-07-18 17:52:58 +0000279 The meaning of the variables is the same as that of the return
280 values from \function{exc_info()} above. (Since there is only one
281 interactive thread, thread-safety is not a concern for these
282 variables, unlike for \code{exc_type} etc.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000283\end{datadesc}
284
Guido van Rossum3e5fe421998-06-10 17:57:44 +0000285\begin{datadesc}{maxint}
Fred Drake72182022001-07-18 17:52:58 +0000286 The largest positive integer supported by Python's regular integer
287 type. This is at least 2**31-1. The largest negative integer is
Fred Drakec05fc7d2001-09-04 18:18:36 +0000288 \code{-maxint-1} --- the asymmetry results from the use of 2's
Fred Drake72182022001-07-18 17:52:58 +0000289 complement binary arithmetic.
Guido van Rossum3e5fe421998-06-10 17:57:44 +0000290\end{datadesc}
291
Fred Drakec05fc7d2001-09-04 18:18:36 +0000292\begin{datadesc}{maxunicode}
293 An integer giving the largest supported code point for a Unicode
294 character. The value of this depends on the configuration option
295 that specifies whether Unicode characters are stored as UCS-2 or
296 UCS-4.
297\end{datadesc}
298
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000299\begin{datadesc}{modules}
Fred Drake0fd72ee1998-03-08 05:43:51 +0000300 This is a dictionary that maps module names to modules which have
301 already been loaded. This can be manipulated to force reloading of
302 modules and other tricks. Note that removing a module from this
303 dictionary is \emph{not} the same as calling
304 \function{reload()}\bifuncindex{reload} on the corresponding module
305 object.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000306\end{datadesc}
307
308\begin{datadesc}{path}
Fred Drake2b67bee1998-01-13 18:35:51 +0000309\indexiii{module}{search}{path}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000310 A list of strings that specifies the search path for modules.
Guido van Rossum54ed2d32002-07-15 16:08:10 +0000311 Initialized from the environment variable \envvar{PYTHONPATH}, plus an
Fred Drake72182022001-07-18 17:52:58 +0000312 installation-dependent default.
Guido van Rossum0a3c7531997-06-02 17:32:41 +0000313
Guido van Rossum54ed2d32002-07-15 16:08:10 +0000314 As initialized upon program startup,
315 the first item of this list, \code{path[0]}, is the directory
Fred Drake72182022001-07-18 17:52:58 +0000316 containing the script that was used to invoke the Python
317 interpreter. If the script directory is not available (e.g. if the
318 interpreter is invoked interactively or if the script is read from
319 standard input), \code{path[0]} is the empty string, which directs
320 Python to search modules in the current directory first. Notice
321 that the script directory is inserted \emph{before} the entries
322 inserted as a result of \envvar{PYTHONPATH}.
Guido van Rossum54ed2d32002-07-15 16:08:10 +0000323
324 A program is free to modify this list for its own purposes.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000325\end{datadesc}
326
Guido van Rossum6b686e91995-07-07 23:00:35 +0000327\begin{datadesc}{platform}
Fred Drake72182022001-07-18 17:52:58 +0000328 This string contains a platform identifier, e.g. \code{'sunos5'} or
329 \code{'linux1'}. This can be used to append platform-specific
330 components to \code{path}, for instance.
Guido van Rossum0a3c7531997-06-02 17:32:41 +0000331\end{datadesc}
332
333\begin{datadesc}{prefix}
Fred Drake72182022001-07-18 17:52:58 +0000334 A string giving the site-specific directory prefix where the
335 platform independent Python files are installed; by default, this is
336 the string \code{'/usr/local'}. This can be set at build time with
337 the \longprogramopt{prefix} argument to the \program{configure}
338 script. The main collection of Python library modules is installed
339 in the directory \code{prefix + '/lib/python\var{version}'} while
Martin v. Löwis4f1cd8b2001-07-26 13:41:06 +0000340 the platform independent header files (all except \file{pyconfig.h})
Fred Drake72182022001-07-18 17:52:58 +0000341 are stored in \code{prefix + '/include/python\var{version}'}, where
342 \var{version} is equal to \code{version[:3]}.
Guido van Rossum6b686e91995-07-07 23:00:35 +0000343\end{datadesc}
344
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000345\begin{datadesc}{ps1}
346\dataline{ps2}
Fred Drakee6cedb31998-04-03 07:05:16 +0000347\index{interpreter prompts}
348\index{prompts, interpreter}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000349 Strings specifying the primary and secondary prompt of the
350 interpreter. These are only defined if the interpreter is in
351 interactive mode. Their initial values in this case are
Fred Drake72182022001-07-18 17:52:58 +0000352 \code{'>\code{>}> '} and \code{'... '}. If a non-string object is
353 assigned to either variable, its \function{str()} is re-evaluated
354 each time the interpreter prepares to read a new interactive
355 command; this can be used to implement a dynamic prompt.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000356\end{datadesc}
357
Guido van Rossum9c51e411995-01-10 10:50:58 +0000358\begin{funcdesc}{setcheckinterval}{interval}
Fred Drake72182022001-07-18 17:52:58 +0000359 Set the interpreter's ``check interval''. This integer value
360 determines how often the interpreter checks for periodic things such
361 as thread switches and signal handlers. The default is \code{10},
362 meaning the check is performed every 10 Python virtual instructions.
363 Setting it to a larger value may increase performance for programs
364 using threads. Setting it to a value \code{<=} 0 checks every
365 virtual instruction, maximizing responsiveness as well as overhead.
Guido van Rossum7f49b7a1995-01-12 12:38:46 +0000366\end{funcdesc}
Guido van Rossum9c51e411995-01-10 10:50:58 +0000367
Fred Drake8940faf2000-10-25 21:02:55 +0000368\begin{funcdesc}{setdefaultencoding}{name}
369 Set the current default string encoding used by the Unicode
370 implementation. If \var{name} does not match any available
371 encoding, \exception{LookupError} is raised. This function is only
372 intended to be used by the \refmodule{site} module implementation
373 and, where needed, by \module{sitecustomize}. Once used by the
374 \refmodule{site} module, it is removed from the \module{sys}
375 module's namespace.
376% Note that \refmodule{site} is not imported if
377% the \programopt{-S} option is passed to the interpreter, in which
378% case this function will remain available.
379 \versionadded{2.0}
380\end{funcdesc}
381
Andrew M. Kuchling28bafb82001-07-19 01:17:15 +0000382\begin{funcdesc}{setdlopenflags}{n}
Fred Drake5d808fb2001-07-18 16:35:05 +0000383 Set the flags used by the interpreter for \cfunction{dlopen()}
384 calls, such as when the interpreter loads extension modules. Among
385 other things, this will enable a lazy resolving of symbols when
Andrew M. Kuchling28bafb82001-07-19 01:17:15 +0000386 importing a module, if called as \code{sys.setdlopenflags(0)}. To
387 share symbols across extension modules, call as
Fred Drake72182022001-07-18 17:52:58 +0000388 \code{sys.setdlopenflags(dl.RTLD_NOW | dl.RTLD_GLOBAL)}. Symbolic
Fred Drake5d808fb2001-07-18 16:35:05 +0000389 names for the flag modules can be either found in the \refmodule{dl}
390 module, or in the \module{DLFCN} module. If \module{DLFCN} is not
Fred Drake72182022001-07-18 17:52:58 +0000391 available, it can be generated from \file{/usr/include/dlfcn.h}
392 using the \program{h2py} script.
Fred Drake5d808fb2001-07-18 16:35:05 +0000393 Availability: \UNIX.
394 \versionadded{2.2}
Martin v. Löwisf0473d52001-07-18 16:17:16 +0000395\end{funcdesc}
396
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000397\begin{funcdesc}{setprofile}{profilefunc}
Fred Drake72182022001-07-18 17:52:58 +0000398 Set the system's profile function,\index{profile function} which
399 allows you to implement a Python source code profiler in
400 Python.\index{profiler} See chapter \ref{profile} for more
401 information on the Python profiler. The system's profile function
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000402 is called similarly to the system's trace function (see
Fred Drake72182022001-07-18 17:52:58 +0000403 \function{settrace()}), but it isn't called for each executed line
Fred Drake64d78632001-10-16 14:54:22 +0000404 of code (only on call and return, but the return event is reported
405 even when an exception has been set). The function is
406 thread-specific, but there is no way for the profiler to know about
407 context switches between threads, so it does not make sense to use
408 this in the presence of multiple threads.
Fred Drake72182022001-07-18 17:52:58 +0000409 Also, its return value is not used, so it can simply return
410 \code{None}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000411\end{funcdesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000412
Jeremy Hyltonee5adfb2000-08-31 19:23:01 +0000413\begin{funcdesc}{setrecursionlimit}{limit}
Fred Drake72182022001-07-18 17:52:58 +0000414 Set the maximum depth of the Python interpreter stack to
415 \var{limit}. This limit prevents infinite recursion from causing an
416 overflow of the C stack and crashing Python.
Jeremy Hyltonee5adfb2000-08-31 19:23:01 +0000417
Fred Drake72182022001-07-18 17:52:58 +0000418 The highest possible limit is platform-dependent. A user may need
419 to set the limit higher when she has a program that requires deep
420 recursion and a platform that supports a higher limit. This should
421 be done with care, because a too-high limit can lead to a crash.
Fred Drake65faf112000-08-31 19:35:56 +0000422\end{funcdesc}
Jeremy Hyltonee5adfb2000-08-31 19:23:01 +0000423
Guido van Rossum3e5fe421998-06-10 17:57:44 +0000424\begin{funcdesc}{settrace}{tracefunc}
Fred Drake72182022001-07-18 17:52:58 +0000425 Set the system's trace function,\index{trace function} which allows
426 you to implement a Python source code debugger in Python. See
427 section \ref{debugger-hooks}, ``How It Works,'' in the chapter on
Fred Drake64d78632001-10-16 14:54:22 +0000428 the Python debugger.\index{debugger} The function is
429 thread-specific; for a debugger to support multiple threads, it must
430 be registered using \function{settrace()} for each thread being
431 debugged.
Guido van Rossum3e5fe421998-06-10 17:57:44 +0000432\end{funcdesc}
Guido van Rossum3e5fe421998-06-10 17:57:44 +0000433
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000434\begin{datadesc}{stdin}
435\dataline{stdout}
436\dataline{stderr}
437 File objects corresponding to the interpreter's standard input,
Fred Drake72182022001-07-18 17:52:58 +0000438 output and error streams. \code{stdin} is used for all interpreter
439 input except for scripts but including calls to
Fred Drake0fd72ee1998-03-08 05:43:51 +0000440 \function{input()}\bifuncindex{input} and
Fred Drake72182022001-07-18 17:52:58 +0000441 \function{raw_input()}\bifuncindex{raw_input}. \code{stdout} is
442 used for the output of \keyword{print} and expression statements and
443 for the prompts of \function{input()} and \function{raw_input()}.
444 The interpreter's own prompts and (almost all of) its error messages
445 go to \code{stderr}. \code{stdout} and \code{stderr} needn't be
446 built-in file objects: any object is acceptable as long as it has a
447 \method{write()} method that takes a string argument. (Changing
448 these objects doesn't affect the standard I/O streams of processes
Fred Drake0fd72ee1998-03-08 05:43:51 +0000449 executed by \function{os.popen()}, \function{os.system()} or the
Fred Drake72182022001-07-18 17:52:58 +0000450 \function{exec*()} family of functions in the \refmodule{os}
451 module.)
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000452\end{datadesc}
453
Guido van Rossum3e5fe421998-06-10 17:57:44 +0000454\begin{datadesc}{__stdin__}
455\dataline{__stdout__}
456\dataline{__stderr__}
Fred Drake72182022001-07-18 17:52:58 +0000457 These objects contain the original values of \code{stdin},
458 \code{stderr} and \code{stdout} at the start of the program. They
459 are used during finalization, and could be useful to restore the
460 actual files to known working file objects in case they have been
461 overwritten with a broken object.
Guido van Rossum3e5fe421998-06-10 17:57:44 +0000462\end{datadesc}
463
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000464\begin{datadesc}{tracebacklimit}
Fred Drake72182022001-07-18 17:52:58 +0000465 When this variable is set to an integer value, it determines the
466 maximum number of levels of traceback information printed when an
467 unhandled exception occurs. The default is \code{1000}. When set
468 to \code{0} or less, all traceback information is suppressed and
469 only the exception type and value are printed.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000470\end{datadesc}
Guido van Rossum0a3c7531997-06-02 17:32:41 +0000471
472\begin{datadesc}{version}
Fred Drake72182022001-07-18 17:52:58 +0000473 A string containing the version number of the Python interpreter
474 plus additional information on the build number and compiler used.
475 It has a value of the form \code{'\var{version}
476 (\#\var{build_number}, \var{build_date}, \var{build_time})
477 [\var{compiler}]'}. The first three characters are used to identify
478 the version in the installation directories (where appropriate on
479 each platform). An example:
Fred Drake38e5d272000-04-03 20:13:55 +0000480
481\begin{verbatim}
482>>> import sys
483>>> sys.version
484'1.5.2 (#0 Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)]'
485\end{verbatim}
486\end{datadesc}
487
Skip Montanaro8e790e72002-09-03 13:25:17 +0000488\begin{datadesc}{api_version}
489 The C API version for this interpreter. Programmers may find this useful
490 when debugging version conflicts between Python and extension
491 modules. \versionadded{2.3}
492\end{datadesc}
493
Fred Drake4d65d732000-04-13 16:54:17 +0000494\begin{datadesc}{version_info}
Fred Drake72182022001-07-18 17:52:58 +0000495 A tuple containing the five components of the version number:
496 \var{major}, \var{minor}, \var{micro}, \var{releaselevel}, and
497 \var{serial}. All values except \var{releaselevel} are integers;
498 the release level is \code{'alpha'}, \code{'beta'},
499 \code{'candidate'}, or \code{'final'}. The \code{version_info}
500 value corresponding to the Python version 2.0 is \code{(2, 0, 0,
501 'final', 0)}.
502 \versionadded{2.0}
Fred Drake4d65d732000-04-13 16:54:17 +0000503\end{datadesc}
504
Fred Drakec05fc7d2001-09-04 18:18:36 +0000505\begin{datadesc}{warnoptions}
506 This is an implementation detail of the warnings framework; do not
507 modify this value. Refer to the \refmodule{warnings} module for
508 more information on the warnings framework.
509\end{datadesc}
510
Fred Drake38e5d272000-04-03 20:13:55 +0000511\begin{datadesc}{winver}
Fred Drake72182022001-07-18 17:52:58 +0000512 The version number used to form registry keys on Windows platforms.
513 This is stored as string resource 1000 in the Python DLL. The value
514 is normally the first three characters of \constant{version}. It is
515 provided in the \module{sys} module for informational purposes;
516 modifying this value has no effect on the registry keys used by
517 Python.
518 Availability: Windows.
Guido van Rossum0a3c7531997-06-02 17:32:41 +0000519\end{datadesc}
Skip Montanaro8a797272002-03-27 17:29:50 +0000520
521
522\begin{seealso}
523 \seemodule{site}
524 {This describes how to use .pth files to extend \code{sys.path}.}
525\end{seealso}