| 5876 | class TestCloseFds(unittest.TestCase): |
| 5877 | |
| 5878 | def get_high_socket_fd(self): |
| 5879 | if WIN32: |
| 5880 | # The child process will not have any socket handles, so |
| 5881 | # calling socket.fromfd() should produce WSAENOTSOCK even |
| 5882 | # if there is a handle of the same number. |
| 5883 | return socket.socket().detach() |
| 5884 | else: |
| 5885 | # We want to produce a socket with an fd high enough that a |
| 5886 | # freshly created child process will not have any fds as high. |
| 5887 | fd = socket.socket().detach() |
| 5888 | to_close = [] |
| 5889 | while fd < 50: |
| 5890 | to_close.append(fd) |
| 5891 | fd = os.dup(fd) |
| 5892 | for x in to_close: |
| 5893 | os.close(x) |
| 5894 | return fd |
| 5895 | |
| 5896 | def close(self, fd): |
| 5897 | if WIN32: |