作業系統工具¶
-
PyObject *PyOS_FSPath(PyObject *path)¶
- 回傳值:新的參照。 為 穩定 ABI 的一部分 自 3.6 版本開始.
Return the file system representation for path. If the object is a
strorbytesobject, then a new strong reference is returned. If the object implements theos.PathLikeinterface, then__fspath__()is returned as long as it is astrorbytesobject. OtherwiseTypeErroris raised andNULLis returned.在 3.6 版被加入.
-
int Py_FdIsInteractive(FILE *fp, const char *filename)¶
Return true (nonzero) if the standard I/O file fp with name filename is deemed interactive. This is the case for files for which
isatty(fileno(fp))is true. If thePyConfig.interactiveis non-zero, this function also returns true if the filename pointer isNULLor if the name is equal to one of the strings'<stdin>'or'???'.This function must not be called before Python is initialized.
-
void PyOS_BeforeFork()¶
- 為 穩定 ABI 的一部分 on platforms with fork() 自 3.7 版本開始.
Function to prepare some internal state before a process fork. This should be called before calling
fork()or any similar function that clones the current process. Only available on systems wherefork()is defined.警告
The C
fork()call should only be made from the "main" thread (of the "main" interpreter). The same is true forPyOS_BeforeFork().在 3.7 版被加入.
-
void PyOS_AfterFork_Parent()¶
- 為 穩定 ABI 的一部分 on platforms with fork() 自 3.7 版本開始.
Function to update some internal state after a process fork. This should be called from the parent process after calling
fork()or any similar function that clones the current process, regardless of whether process cloning was successful. Only available on systems wherefork()is defined.警告
The C
fork()call should only be made from the "main" thread (of the "main" interpreter). The same is true forPyOS_AfterFork_Parent().在 3.7 版被加入.
-
void PyOS_AfterFork_Child()¶
- 為 穩定 ABI 的一部分 on platforms with fork() 自 3.7 版本開始.
Function to update internal interpreter state after a process fork. This must be called from the child process after calling
fork(), or any similar function that clones the current process, if there is any chance the process will call back into the Python interpreter. Only available on systems wherefork()is defined.警告
The C
fork()call should only be made from the "main" thread (of the "main" interpreter). The same is true forPyOS_AfterFork_Child().在 3.7 版被加入.
也參考
os.register_at_fork()allows registering custom Python functions to be called byPyOS_BeforeFork(),PyOS_AfterFork_Parent()andPyOS_AfterFork_Child().
-
void PyOS_AfterFork()¶
- 為 穩定 ABI 的一部分 on platforms with fork().
Function to update some internal state after a process fork; this should be called in the new process if the Python interpreter will continue to be used. If a new executable is loaded into the new process, this function does not need to be called.
在 3.7 版之後被棄用: This function is superseded by
PyOS_AfterFork_Child().
-
int PyOS_CheckStack()¶
- 為 穩定 ABI 的一部分 on platforms with USE_STACKCHECK 自 3.7 版本開始.
Return true when the interpreter runs out of stack space. This is a reliable check, but is only available when
USE_STACKCHECKis defined (currently on certain versions of Windows using the Microsoft Visual C++ compiler).USE_STACKCHECKwill be defined automatically; you should never change the definition in your own code.
-
typedef void (*PyOS_sighandler_t)(int)¶
- 為 穩定 ABI 的一部分.
-
PyOS_sighandler_t PyOS_getsig(int i)¶
- 為 穩定 ABI 的一部分.
Return the current signal handler for signal i. This is a thin wrapper around either
sigaction()orsignal(). Do not call those functions directly!
-
PyOS_sighandler_t PyOS_setsig(int i, PyOS_sighandler_t h)¶
- 為 穩定 ABI 的一部分.
Set the signal handler for signal i to be h; return the old signal handler. This is a thin wrapper around either
sigaction()orsignal(). Do not call those functions directly!
-
int PyOS_InterruptOccurred(void)¶
- 為 穩定 ABI 的一部分.
Check if a
SIGINTsignal has been received.Returns
1if aSIGINThas occurred and clears the signal flag, or0otherwise.In most cases, you should prefer
PyErr_CheckSignals()over this function.PyErr_CheckSignals()invokes the appropriate signal handlers for all pending signals, allowing Python code to handle the signal properly. This function only detectsSIGINTand does not invoke any Python signal handlers.This function is async-signal-safe and this function cannot fail. The caller must hold an attached thread state.
-
wchar_t *Py_DecodeLocale(const char *arg, size_t *size)¶
- 為 穩定 ABI 的一部分 自 3.7 版本開始.
警告
This function should not be called directly: use the
PyConfigAPI with thePyConfig_SetBytesString()function which ensures that Python is preinitialized.This function must not be called before Python is preinitialized and so that the LC_CTYPE locale is properly configured: see the
Py_PreInitialize()function.Decode a byte string from the filesystem encoding and error handler. If the error handler is surrogateescape error handler, undecodable bytes are decoded as characters in range U+DC80..U+DCFF; and if a byte sequence can be decoded as a surrogate character, the bytes are escaped using the surrogateescape error handler instead of decoding them.
Return a pointer to a newly allocated wide character string, use
PyMem_RawFree()to free the memory. If size is notNULL, write the number of wide characters excluding the null character into*sizeReturn
NULLon decoding error or memory allocation error. If size is notNULL,*sizeis set to(size_t)-1on memory error or set to(size_t)-2on decoding error.The filesystem encoding and error handler are selected by
PyConfig_Read(): seefilesystem_encodingandfilesystem_errorsmembers ofPyConfig.Decoding errors should never happen, unless there is a bug in the C library.
Use the
Py_EncodeLocale()function to encode the character string back to a byte string.也參考
The
PyUnicode_DecodeFSDefaultAndSize()andPyUnicode_DecodeLocaleAndSize()functions.在 3.5 版被加入.
在 3.7 版的變更: The function now uses the UTF-8 encoding in the Python UTF-8 Mode.
在 3.8 版的變更: The function now uses the UTF-8 encoding on Windows if
PyPreConfig.legacy_windows_fs_encodingis zero;
-
char *Py_EncodeLocale(const wchar_t *text, size_t *error_pos)¶
- 為 穩定 ABI 的一部分 自 3.7 版本開始.
Encode a wide character string to the filesystem encoding and error handler. If the error handler is surrogateescape error handler, surrogate characters in the range U+DC80..U+DCFF are converted to bytes 0x80..0xFF.
Return a pointer to a newly allocated byte string, use
PyMem_Free()to free the memory. ReturnNULLon encoding error or memory allocation error.If error_pos is not
NULL,*error_posis set to(size_t)-1on success, or set to the index of the invalid character on encoding error.The filesystem encoding and error handler are selected by
PyConfig_Read(): seefilesystem_encodingandfilesystem_errorsmembers ofPyConfig.Use the
Py_DecodeLocale()function to decode the bytes string back to a wide character string.警告
This function must not be called before Python is preinitialized and so that the LC_CTYPE locale is properly configured: see the
Py_PreInitialize()function.也參考
The
PyUnicode_EncodeFSDefault()andPyUnicode_EncodeLocale()functions.在 3.5 版被加入.
在 3.7 版的變更: The function now uses the UTF-8 encoding in the Python UTF-8 Mode.
在 3.8 版的變更: The function now uses the UTF-8 encoding on Windows if
PyPreConfig.legacy_windows_fs_encodingis zero.