Issue 45944: Avoid calling isatty() for most open() calls
Issue45944
Created on 2021-12-01 05:08 by collinanderson, last changed 2022-04-11 14:59 by admin.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 29870 | open | collinanderson, 2021-12-01 05:11 | |
| Messages (3) | |||
|---|---|---|---|
| msg407427 - (view) | Author: Collin Anderson (collinanderson) * | Date: 2021-12-01 05:12 | |
isatty() is a system call on linux. Most open()s are files, and we're already getting the size of the file. If it has a size, then we know it's not a atty, and can avoid calling it. |
|||
| msg407434 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * ![]() |
Date: 2021-12-01 09:22 | |
What if change FileIO.isatty() instead? If make it returning False without invoking a system call if the file size is non-zero it will eliminate the need to expose _size. |
|||
| msg407444 - (view) | Author: Eryk Sun (eryksun) * ![]() |
Date: 2021-12-01 11:53 | |
> make it returning False without invoking a system call if the file > size is non-zero it will eliminate the need to expose _size. I suggest using the file type instead of the size. There's no reason to call isatty() if it's not an S_IFCHR file. This will avoid calling isatty() on regular files that happen to be empty. In Windows, isatty(fd) is based solely on the file type, which is flagged in the fd record when a file descriptor is opened for a native file handle. It's not a system call, but it's also nearly worthless for how isatty() is typically used, since it's true for any S_IFCHR file (e.g. con, nul, com1). |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:53 | admin | set | github: 90102 |
| 2021-12-01 11:53:13 | eryksun | set | nosy:
+ eryksun messages: + msg407444 |
| 2021-12-01 09:24:45 | serhiy.storchaka | set | nosy:
+ pitrou, benjamin.peterson, stutzbach versions: - Python 3.6, Python 3.7, Python 3.8, Python 3.9, Python 3.10 |
| 2021-12-01 09:22:53 | serhiy.storchaka | set | nosy:
+ serhiy.storchaka messages: + msg407434 |
| 2021-12-01 05:12:39 | collinanderson | set | messages: + msg407427 |
| 2021-12-01 05:11:58 | collinanderson | set | keywords:
+ patch stage: patch review pull_requests: + pull_request28096 |
| 2021-12-01 05:08:15 | collinanderson | create | |

