#!/usr/bin/env python from __future__ import print_function import os import readline import sys if sys.version_info.major >= 3: raw_input = input def waste_n_file_descriptors(n): open_fds = [] for _ in range(n): open_fds.append(os.open('/dev/null', os.O_RDONLY)) print('Opened file descriptors', open_fds[0], '-', open_fds[-1]) def main(): if len(sys.argv) < 2: print('Supply the number of file descriptors to open on the command line.') print('Values >FD_SETSIZE-3 may cause a crash when the bug is present.') print('1024 and 32768 are some common FD_SETSIZE values in the wild.') sys.exit(1) print('Not all values will cause a crash even if they scribble on memory.') print('Pro tip: Compile your interpreter with ASAN for nicer diagnostics.') waste_n_file_descriptors(int(sys.argv[1])) old_stdin = sys.stdin try: sys.stdin = open('/dev/tty', 'r') raw_input('If this does not crash, just hit Enter.') finally: sys.stdin = old_stdin if __name__ == '__main__': main()