File: greenio_double_close_219.py

package info (click to toggle)
python-eventlet 0.26.1-7%2Bdeb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,916 kB
  • sloc: python: 24,898; makefile: 98
file content (18 lines) | stat: -rw-r--r-- 587 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
__test__ = False

if __name__ == '__main__':
    import eventlet
    eventlet.monkey_patch()
    import subprocess
    import gc

    p = subprocess.Popen(['ls'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    # the following line creates a _SocketDuckForFd(3) and .close()s it, but the
    # object has not been collected by the GC yet
    p.communicate()

    f = open('/dev/null', 'rb')    # f.fileno() == 3
    gc.collect() # this calls the __del__ of _SocketDuckForFd(3), close()ing it again

    f.close() # OSError, because the fd 3 has already been closed
    print('pass')