New submission from Eryk Sun <eryk...@gmail.com>:
During startup, is_valid_fd() in Python/pylifecycle.c is called to validate stdin, stdout, and stderr. Performance isn't critical here, but every bit helps in reducing startup time. In my tests, implementing this check in Windows via GetFileType((HANDLE)_get_osfhandle(fd)) is 5-6 times faster than close(dup(fd)). For example: #if defined(MS_WINDOWS) HANDLE hfile; _Py_BEGIN_SUPPRESS_IPH hfile = (HANDLE)_get_osfhandle(fd); _Py_END_SUPPRESS_IPH return (hfile != INVALID_HANDLE_VALUE && GetFileType(hfile) != FILE_TYPE_UNKNOWN); #endif ---------- components: Interpreter Core, Windows keywords: easy (C) messages: 407221 nosy: eryksun, paul.moore, steve.dower, tim.golden, zach.ware priority: normal severity: normal stage: needs patch status: open title: Use WinAPI GetFileType() in is_valid_fd() type: enhancement versions: Python 3.11 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue45919> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com