{"record":{"id":"8fb3e20113284f5c","repo":"aosabook/500lines","slug":"inotify-init-error","errorCode":null,"errorMessage":"inotify_init() error: {}","messagePattern":"inotify_init\\(\\) error: (.+?)","errorType":"exception","errorClass":"OSError","httpStatus":null,"severity":"error","filePath":"contingent/code/contingent/io.py","lineNumber":41,"sourceCode":"    # offer inotify_wait, and fall back to looping_wait_on().\n    _setup_libc()\n    return inotify_wait_on(paths)\n\ndef looping_wait_on(paths):\n    start = time.time()\n    changed_paths = []\n    while not changed_paths:\n        time.sleep(0.5)\n        changed_paths = [path for path in paths\n                         if os.stat(path).st_mtime > start]\n    return changed_paths\n\ndef inotify_wait_on(paths):\n    paths = [path.encode('ascii') for path in paths]\n    fd = _libc.inotify_init()\n    descriptors = {}\n    if fd == -1:\n        raise OSError('inotify_init() error: {}'.format(\n            os.strerror(ctypes.get_errno())))\n    try:\n        for path in paths:\n            rv = _libc.inotify_add_watch(fd, path, 0x2)\n            if rv == -1:\n                raise OSError('inotify_add_watch() error: {}'.format(\n                    os.strerror(ctypes.get_errno())))\n            descriptors[rv] = path\n        buf = os.read(fd, 1024)\n        # TODO: continue with some more reads with 0.1 second timeouts\n        # to empty the list of roughly-simultaneous events before\n        # closing our file descriptor and returning?\n    finally:\n        pass #os.close(fd)\n    time.sleep(0.1)  # until above TODO is done\n    wd, mask, cookie, name_length = struct.unpack('iIII', buf)\n    return [descriptors[wd].decode('ascii')]\n","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/aosabook/500lines/blob/fba689d101eb5600f5c8f4d7fd79912498e950e2/contingent/code/contingent/io.py#L23-L59","documentation":"Error \"inotify_init() error: {}\" thrown in aosabook/500lines.","triggerScenarios":"Thrown at contingent/code/contingent/io.py:41 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Run on a Linux kernel with inotify support; on other platforms use the polling fallback wait_on instead of inotify_wait_on.","Raise the per-process file descriptor limit (ulimit -n) if inotify_init fails with EMFILE.","Check /proc/sys/fs/inotify/max_user_instances and increase it if the instance limit is reached."],"exampleFix":"sysctl fs.inotify.max_user_instances=512  # or catch OSError and fall back to wait_on(paths)","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fba689d101eb5600f5c8f4d7fd79912498e950e2","analyzedAt":"2026-08-13T06:26:32.792Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}