{"record":{"id":"cd4afa6562951c53","repo":"ytdl-org/youtube-dl","slug":"locking-file-failed-r","errorCode":null,"errorMessage":"Locking file failed: %r","messagePattern":"Locking file failed: %r","errorType":"exception","errorClass":"OSError","httpStatus":null,"severity":"error","filePath":"youtube_dl/utils.py","lineNumber":3524,"sourceCode":"        ctypes.wintypes.DWORD,      # dwReserved\n        ctypes.wintypes.DWORD,      # nNumberOfBytesToLockLow\n        ctypes.wintypes.DWORD,      # nNumberOfBytesToLockHigh\n        ctypes.POINTER(OVERLAPPED)  # Overlapped\n    ]\n    UnlockFileEx.restype = ctypes.wintypes.BOOL\n    whole_low = 0xffffffff\n    whole_high = 0x7fffffff\n\n    def _lock_file(f, exclusive):\n        overlapped = OVERLAPPED()\n        overlapped.Offset = 0\n        overlapped.OffsetHigh = 0\n        overlapped.hEvent = 0\n        f._lock_file_overlapped_p = ctypes.pointer(overlapped)\n        handle = msvcrt.get_osfhandle(f.fileno())\n        if not LockFileEx(handle, 0x2 if exclusive else 0x0, 0,\n                          whole_low, whole_high, f._lock_file_overlapped_p):\n            raise OSError('Locking file failed: %r' % ctypes.FormatError())\n\n    def _unlock_file(f):\n        assert f._lock_file_overlapped_p\n        handle = msvcrt.get_osfhandle(f.fileno())\n        if not UnlockFileEx(handle, 0,\n                            whole_low, whole_high, f._lock_file_overlapped_p):\n            raise OSError('Unlocking file failed: %r' % ctypes.FormatError())\n\nelse:\n    # Some platforms, such as Jython, is missing fcntl\n    try:\n        import fcntl\n\n        def _lock_file(f, exclusive):\n            fcntl.flock(f, fcntl.LOCK_EX if exclusive else fcntl.LOCK_SH)\n\n        def _unlock_file(f):\n            fcntl.flock(f, fcntl.LOCK_UN)","sourceCodeStart":3506,"sourceCodeEnd":3542,"githubUrl":"https://github.com/ytdl-org/youtube-dl/blob/956b8c585591b401a543e409accb163eeaaa1193/youtube_dl/utils.py#L3506-L3542","documentation":"Error \"Locking file failed: %r\" thrown in ytdl-org/youtube-dl.","triggerScenarios":"Thrown at youtube_dl/utils.py:3524 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Close other processes using the file and check filesystem locking support."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"956b8c585591b401a543e409accb163eeaaa1193","analyzedAt":"2026-08-14T18:59:47.863Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}