5 Operating System Utilities
6 ==========================
9 .. cfunction:: int Py_FdIsInteractive(FILE *fp, const char *filename)
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))``
13 is true. If the global flag :cdata:`Py_InteractiveFlag` is true, this function
14 also returns true if the *filename* pointer is *NULL* or if the name is equal to
15 one of the strings ``'<stdin>'`` or ``'???'``.
18 .. cfunction:: void PyOS_AfterFork()
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
26 .. cfunction:: int PyOS_CheckStack()
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
35 .. cfunction:: PyOS_sighandler_t PyOS_getsig(int i)
37 Return the current signal handler for signal *i*. This is a thin wrapper around
38 either :cfunc:`sigaction` or :cfunc:`signal`. Do not call those functions
39 directly! :ctype:`PyOS_sighandler_t` is a typedef alias for :ctype:`void
43 .. cfunction:: PyOS_sighandler_t PyOS_setsig(int i, PyOS_sighandler_t h)
45 Set the signal handler for signal *i* to be *h*; return the old signal handler.
46 This is a thin wrapper around either :cfunc:`sigaction` or :cfunc:`signal`. Do
47 not call those functions directly! :ctype:`PyOS_sighandler_t` is a typedef
48 alias for :ctype:`void (\*)(int)`.
55 These are utility functions that make functionality from the :mod:`sys` module
56 accessible 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.
59 .. cfunction:: PyObject *PySys_GetObject(char *name)
61 Return the object *name* from the :mod:`sys` module or *NULL* if it does
62 not exist, without setting an exception.
64 .. cfunction:: FILE *PySys_GetFile(char *name, FILE *def)
66 Return the :ctype:`FILE*` associated with the object *name* in the
67 :mod:`sys` module, or *def* if *name* is not in the module or is not associated
68 with a :ctype:`FILE*`.
70 .. cfunction:: int PySys_SetObject(char *name, PyObject *v)
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``
76 .. cfunction:: void PySys_ResetWarnOptions()
78 Reset :data:`sys.warnoptions` to an empty list.
80 .. cfunction:: void PySys_AddWarnOption(char *s)
82 Append *s* to :data:`sys.warnoptions`.
84 .. cfunction:: void PySys_SetPath(char *path)
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).
90 .. cfunction:: void PySys_WriteStdout(const char *format, ...)
92 Write the output string described by *format* to :data:`sys.stdout`. No
93 exceptions are raised, even if truncation occurs (see below).
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.
103 If a problem occurs, or :data:`sys.stdout` is unset, the formatted message
104 is written to the real (C level) *stdout*.
106 .. cfunction:: void PySys_WriteStderr(const char *format, ...)
108 As above, but write to :data:`sys.stderr` or *stderr* instead.
117 .. cfunction:: void Py_FatalError(const char *message)
119 .. index:: single: abort()
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
125 function :cfunc:`abort` is called which will attempt to produce a :file:`core`
129 .. cfunction:: void Py_Exit(int status)
132 single: Py_Finalize()
135 Exit the current process. This calls :cfunc:`Py_Finalize` and then calls the
136 standard C library function ``exit(status)``.
139 .. cfunction:: int Py_AtExit(void (*func) ())
142 single: Py_Finalize()
143 single: cleanup functions
145 Register a cleanup function to be called by :cfunc:`Py_Finalize`. The cleanup
146 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,
148 :cfunc:`Py_AtExit` returns ``0``; on failure, it returns ``-1``. The cleanup
149 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*.