You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

180 lines
6.4 KiB

  1. .. highlightlang:: c
  2. .. _os:
  3. Operating System Utilities
  4. ==========================
  5. .. c:function:: int Py_FdIsInteractive(FILE *fp, const char *filename)
  6. Return true (nonzero) if the standard I/O file *fp* with name *filename* is
  7. deemed interactive. This is the case for files for which ``isatty(fileno(fp))``
  8. is true. If the global flag :c:data:`Py_InteractiveFlag` is true, this function
  9. also returns true if the *filename* pointer is *NULL* or if the name is equal to
  10. one of the strings ``'<stdin>'`` or ``'???'``.
  11. .. c:function:: void PyOS_AfterFork()
  12. Function to update some internal state after a process fork; this should be
  13. called in the new process if the Python interpreter will continue to be used.
  14. If a new executable is loaded into the new process, this function does not need
  15. to be called.
  16. .. c:function:: int PyOS_CheckStack()
  17. Return true when the interpreter runs out of stack space. This is a reliable
  18. check, but is only available when :const:`USE_STACKCHECK` is defined (currently
  19. on Windows using the Microsoft Visual C++ compiler). :const:`USE_STACKCHECK`
  20. will be defined automatically; you should never change the definition in your
  21. own code.
  22. .. c:function:: PyOS_sighandler_t PyOS_getsig(int i)
  23. Return the current signal handler for signal *i*. This is a thin wrapper around
  24. either :c:func:`sigaction` or :c:func:`signal`. Do not call those functions
  25. directly! :c:type:`PyOS_sighandler_t` is a typedef alias for :c:type:`void
  26. (\*)(int)`.
  27. .. c:function:: PyOS_sighandler_t PyOS_setsig(int i, PyOS_sighandler_t h)
  28. Set the signal handler for signal *i* to be *h*; return the old signal handler.
  29. This is a thin wrapper around either :c:func:`sigaction` or :c:func:`signal`. Do
  30. not call those functions directly! :c:type:`PyOS_sighandler_t` is a typedef
  31. alias for :c:type:`void (\*)(int)`.
  32. .. _systemfunctions:
  33. System Functions
  34. ================
  35. These are utility functions that make functionality from the :mod:`sys` module
  36. accessible to C code. They all work with the current interpreter thread's
  37. :mod:`sys` module's dict, which is contained in the internal thread state structure.
  38. .. c:function:: PyObject *PySys_GetObject(char *name)
  39. Return the object *name* from the :mod:`sys` module or *NULL* if it does
  40. not exist, without setting an exception.
  41. .. c:function:: int PySys_SetObject(char *name, PyObject *v)
  42. Set *name* in the :mod:`sys` module to *v* unless *v* is *NULL*, in which
  43. case *name* is deleted from the sys module. Returns ``0`` on success, ``-1``
  44. on error.
  45. .. c:function:: void PySys_ResetWarnOptions()
  46. Reset :data:`sys.warnoptions` to an empty list.
  47. .. c:function:: void PySys_AddWarnOption(wchar_t *s)
  48. Append *s* to :data:`sys.warnoptions`.
  49. .. c:function:: void PySys_AddWarnOptionUnicode(PyObject *unicode)
  50. Append *unicode* to :data:`sys.warnoptions`.
  51. .. c:function:: void PySys_SetPath(wchar_t *path)
  52. Set :data:`sys.path` to a list object of paths found in *path* which should
  53. be a list of paths separated with the platform's search path delimiter
  54. (``:`` on Unix, ``;`` on Windows).
  55. .. c:function:: void PySys_WriteStdout(const char *format, ...)
  56. Write the output string described by *format* to :data:`sys.stdout`. No
  57. exceptions are raised, even if truncation occurs (see below).
  58. *format* should limit the total size of the formatted output string to
  59. 1000 bytes or less -- after 1000 bytes, the output string is truncated.
  60. In particular, this means that no unrestricted "%s" formats should occur;
  61. these should be limited using "%.<N>s" where <N> is a decimal number
  62. calculated so that <N> plus the maximum size of other formatted text does not
  63. exceed 1000 bytes. Also watch out for "%f", which can print hundreds of
  64. digits for very large numbers.
  65. If a problem occurs, or :data:`sys.stdout` is unset, the formatted message
  66. is written to the real (C level) *stdout*.
  67. .. c:function:: void PySys_WriteStderr(const char *format, ...)
  68. As :c:func:`PySys_WriteStdout`, but write to :data:`sys.stderr` or *stderr*
  69. instead.
  70. .. c:function:: void PySys_FormatStdout(const char *format, ...)
  71. Function similar to PySys_WriteStdout() but format the message using
  72. :c:func:`PyUnicode_FromFormatV` and don't truncate the message to an
  73. arbitrary length.
  74. .. versionadded:: 3.2
  75. .. c:function:: void PySys_FormatStderr(const char *format, ...)
  76. As :c:func:`PySys_FormatStdout`, but write to :data:`sys.stderr` or *stderr*
  77. instead.
  78. .. versionadded:: 3.2
  79. .. c:function:: void PySys_AddXOption(const wchar_t *s)
  80. Parse *s* as a set of :option:`-X` options and add them to the current
  81. options mapping as returned by :c:func:`PySys_GetXOptions`.
  82. .. versionadded:: 3.2
  83. .. c:function:: PyObject *PySys_GetXOptions()
  84. Return the current dictionary of :option:`-X` options, similarly to
  85. :data:`sys._xoptions`. On error, *NULL* is returned and an exception is
  86. set.
  87. .. versionadded:: 3.2
  88. .. _processcontrol:
  89. Process Control
  90. ===============
  91. .. c:function:: void Py_FatalError(const char *message)
  92. .. index:: single: abort()
  93. Print a fatal error message and kill the process. No cleanup is performed.
  94. This function should only be invoked when a condition is detected that would
  95. make it dangerous to continue using the Python interpreter; e.g., when the
  96. object administration appears to be corrupted. On Unix, the standard C library
  97. function :c:func:`abort` is called which will attempt to produce a :file:`core`
  98. file.
  99. .. c:function:: void Py_Exit(int status)
  100. .. index::
  101. single: Py_Finalize()
  102. single: exit()
  103. Exit the current process. This calls :c:func:`Py_Finalize` and then calls the
  104. standard C library function ``exit(status)``.
  105. .. c:function:: int Py_AtExit(void (*func) ())
  106. .. index::
  107. single: Py_Finalize()
  108. single: cleanup functions
  109. Register a cleanup function to be called by :c:func:`Py_Finalize`. The cleanup
  110. function will be called with no arguments and should return no value. At most
  111. 32 cleanup functions can be registered. When the registration is successful,
  112. :c:func:`Py_AtExit` returns ``0``; on failure, it returns ``-1``. The cleanup
  113. function registered last is called first. Each cleanup function will be called
  114. at most once. Since Python's internal finalization will have completed before
  115. the cleanup function, no Python APIs should be called by *func*.