| 5543 | class TestCloseFds(unittest.TestCase): |
| 5544 | |
| 5545 | def get_high_socket_fd(self): |
| 5546 | if WIN32: |
| 5547 | # The child process will not have any socket handles, so |
| 5548 | # calling socket.fromfd() should produce WSAENOTSOCK even |
| 5549 | # if there is a handle of the same number. |
| 5550 | return socket.socket().detach() |
| 5551 | else: |
| 5552 | # We want to produce a socket with an fd high enough that a |
| 5553 | # freshly created child process will not have any fds as high. |
| 5554 | fd = socket.socket().detach() |
| 5555 | to_close = [] |
| 5556 | while fd < 50: |
| 5557 | to_close.append(fd) |
| 5558 | fd = os.dup(fd) |
| 5559 | for x in to_close: |
| 5560 | os.close(x) |
| 5561 | return fd |
| 5562 | |
| 5563 | def close(self, fd): |
| 5564 | if WIN32: |