blob: d354e9f57fef2ec9c8e299072361fe28d6a5f328 [file] [log] [blame]
Georg Brandl79e3d552008-01-19 22:14:27 +00001.. highlightlang:: c
2
3.. _os:
4
5Operating System Utilities
6==========================
7
8
Sandro Tosi98ed08f2012-01-14 16:42:02 +01009.. c:function:: int Py_FdIsInteractive(FILE *fp, const char *filename)
Georg Brandl79e3d552008-01-19 22:14:27 +000010
11 Return true (nonzero) if the standard I/O file *fp* with name *filename* is
12 deemed interactive. This is the case for files for which ``isatty(fileno(fp))``
Sandro Tosi98ed08f2012-01-14 16:42:02 +010013 is true. If the global flag :c:data:`Py_InteractiveFlag` is true, this function
Georg Brandl79e3d552008-01-19 22:14:27 +000014 also returns true if the *filename* pointer is *NULL* or if the name is equal to
15 one of the strings ``'<stdin>'`` or ``'???'``.
16
17
Sandro Tosi98ed08f2012-01-14 16:42:02 +010018.. c:function:: void PyOS_AfterFork()
Georg Brandl79e3d552008-01-19 22:14:27 +000019
20 Function to update some internal state after a process fork; this should be
21 called in the new process if the Python interpreter will continue to be used.
22 If a new executable is loaded into the new process, this function does not need
23 to be called.
24
25
Sandro Tosi98ed08f2012-01-14 16:42:02 +010026.. c:function:: int PyOS_CheckStack()
Georg Brandl79e3d552008-01-19 22:14:27 +000027
28 Return true when the interpreter runs out of stack space. This is a reliable
29 check, but is only available when :const:`USE_STACKCHECK` is defined (currently
30 on Windows using the Microsoft Visual C++ compiler). :const:`USE_STACKCHECK`
31 will be defined automatically; you should never change the definition in your
32 own code.
33
34
Sandro Tosi98ed08f2012-01-14 16:42:02 +010035.. c:function:: PyOS_sighandler_t PyOS_getsig(int i)
Georg Brandl79e3d552008-01-19 22:14:27 +000036
37 Return the current signal handler for signal *i*. This is a thin wrapper around
Sandro Tosi98ed08f2012-01-14 16:42:02 +010038 either :c:func:`sigaction` or :c:func:`signal`. Do not call those functions
39 directly! :c:type:`PyOS_sighandler_t` is a typedef alias for :c:type:`void
Georg Brandl79e3d552008-01-19 22:14:27 +000040 (\*)(int)`.
41
42
Sandro Tosi98ed08f2012-01-14 16:42:02 +010043.. c:function:: PyOS_sighandler_t PyOS_setsig(int i, PyOS_sighandler_t h)
Georg Brandl79e3d552008-01-19 22:14:27 +000044
45 Set the signal handler for signal *i* to be *h*; return the old signal handler.
Sandro Tosi98ed08f2012-01-14 16:42:02 +010046 This is a thin wrapper around either :c:func:`sigaction` or :c:func:`signal`. Do
47 not call those functions directly! :c:type:`PyOS_sighandler_t` is a typedef
48 alias for :c:type:`void (\*)(int)`.
Georg Brandl79e3d552008-01-19 22:14:27 +000049
50.. _systemfunctions:
51
52System Functions
53================
54
55These are utility functions that make functionality from the :mod:`sys` module
56accessible to C code. They all work with the current interpreter thread's
57:mod:`sys` module's dict, which is contained in the internal thread state structure.
58
Sandro Tosi98ed08f2012-01-14 16:42:02 +010059.. c:function:: PyObject *PySys_GetObject(char *name)
Georg Brandl79e3d552008-01-19 22:14:27 +000060
61 Return the object *name* from the :mod:`sys` module or *NULL* if it does
62 not exist, without setting an exception.
63
Sandro Tosi98ed08f2012-01-14 16:42:02 +010064.. c:function:: FILE *PySys_GetFile(char *name, FILE *def)
Georg Brandl79e3d552008-01-19 22:14:27 +000065
Sandro Tosi98ed08f2012-01-14 16:42:02 +010066 Return the :c:type:`FILE*` associated with the object *name* in the
Georg Brandl79e3d552008-01-19 22:14:27 +000067 :mod:`sys` module, or *def* if *name* is not in the module or is not associated
Sandro Tosi98ed08f2012-01-14 16:42:02 +010068 with a :c:type:`FILE*`.
Georg Brandl79e3d552008-01-19 22:14:27 +000069
Sandro Tosi98ed08f2012-01-14 16:42:02 +010070.. c:function:: int PySys_SetObject(char *name, PyObject *v)
Georg Brandl79e3d552008-01-19 22:14:27 +000071
72 Set *name* in the :mod:`sys` module to *v* unless *v* is *NULL*, in which
73 case *name* is deleted from the sys module. Returns ``0`` on success, ``-1``
74 on error.
75
Sandro Tosi98ed08f2012-01-14 16:42:02 +010076.. c:function:: void PySys_ResetWarnOptions()
Georg Brandl79e3d552008-01-19 22:14:27 +000077
78 Reset :data:`sys.warnoptions` to an empty list.
79
Sandro Tosi98ed08f2012-01-14 16:42:02 +010080.. c:function:: void PySys_AddWarnOption(char *s)
Georg Brandl79e3d552008-01-19 22:14:27 +000081
82 Append *s* to :data:`sys.warnoptions`.
83
Sandro Tosi98ed08f2012-01-14 16:42:02 +010084.. c:function:: void PySys_SetPath(char *path)
Georg Brandl79e3d552008-01-19 22:14:27 +000085
86 Set :data:`sys.path` to a list object of paths found in *path* which should
87 be a list of paths separated with the platform's search path delimiter
88 (``:`` on Unix, ``;`` on Windows).
89
Sandro Tosi98ed08f2012-01-14 16:42:02 +010090.. c:function:: void PySys_WriteStdout(const char *format, ...)
Georg Brandl79e3d552008-01-19 22:14:27 +000091
92 Write the output string described by *format* to :data:`sys.stdout`. No
93 exceptions are raised, even if truncation occurs (see below).
94
95 *format* should limit the total size of the formatted output string to
96 1000 bytes or less -- after 1000 bytes, the output string is truncated.
97 In particular, this means that no unrestricted "%s" formats should occur;
98 these should be limited using "%.<N>s" where <N> is a decimal number
99 calculated so that <N> plus the maximum size of other formatted text does not
100 exceed 1000 bytes. Also watch out for "%f", which can print hundreds of
101 digits for very large numbers.
102
103 If a problem occurs, or :data:`sys.stdout` is unset, the formatted message
104 is written to the real (C level) *stdout*.
105
Sandro Tosi98ed08f2012-01-14 16:42:02 +0100106.. c:function:: void PySys_WriteStderr(const char *format, ...)
Georg Brandl79e3d552008-01-19 22:14:27 +0000107
108 As above, but write to :data:`sys.stderr` or *stderr* instead.
109
110
111.. _processcontrol:
112
113Process Control
114===============
115
116
Sandro Tosi98ed08f2012-01-14 16:42:02 +0100117.. c:function:: void Py_FatalError(const char *message)
Georg Brandl79e3d552008-01-19 22:14:27 +0000118
119 .. index:: single: abort()
120
121 Print a fatal error message and kill the process. No cleanup is performed.
122 This function should only be invoked when a condition is detected that would
123 make it dangerous to continue using the Python interpreter; e.g., when the
124 object administration appears to be corrupted. On Unix, the standard C library
Sandro Tosi98ed08f2012-01-14 16:42:02 +0100125 function :c:func:`abort` is called which will attempt to produce a :file:`core`
Georg Brandl79e3d552008-01-19 22:14:27 +0000126 file.
127
128
Sandro Tosi98ed08f2012-01-14 16:42:02 +0100129.. c:function:: void Py_Exit(int status)
Georg Brandl79e3d552008-01-19 22:14:27 +0000130
131 .. index::
132 single: Py_Finalize()
133 single: exit()
134
Sandro Tosi98ed08f2012-01-14 16:42:02 +0100135 Exit the current process. This calls :c:func:`Py_Finalize` and then calls the
Georg Brandl79e3d552008-01-19 22:14:27 +0000136 standard C library function ``exit(status)``.
137
138
Sandro Tosi98ed08f2012-01-14 16:42:02 +0100139.. c:function:: int Py_AtExit(void (*func) ())
Georg Brandl79e3d552008-01-19 22:14:27 +0000140
141 .. index::
142 single: Py_Finalize()
143 single: cleanup functions
144
Sandro Tosi98ed08f2012-01-14 16:42:02 +0100145 Register a cleanup function to be called by :c:func:`Py_Finalize`. The cleanup
Georg Brandl79e3d552008-01-19 22:14:27 +0000146 function will be called with no arguments and should return no value. At most
147 32 cleanup functions can be registered. When the registration is successful,
Sandro Tosi98ed08f2012-01-14 16:42:02 +0100148 :c:func:`Py_AtExit` returns ``0``; on failure, it returns ``-1``. The cleanup
Georg Brandl79e3d552008-01-19 22:14:27 +0000149 function registered last is called first. Each cleanup function will be called
150 at most once. Since Python's internal finalization will have completed before
151 the cleanup function, no Python APIs should be called by *func*.