{"record":{"id":"df4d96785c302b88","repo":"ytdl-org/youtube-dl","slug":"unlocking-file-failed-r","errorCode":null,"errorMessage":"Unlocking file failed: %r","messagePattern":"Unlocking file failed: %r","errorType":"exception","errorClass":"OSError","httpStatus":null,"severity":"error","filePath":"youtube_dl/utils.py","lineNumber":3531,"sourceCode":"    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)\n    except ImportError:\n        UNSUPPORTED_MSG = 'file locking is not supported on this platform'\n\n        def _lock_file(f, exclusive):\n            raise IOError(UNSUPPORTED_MSG)\n\n        def _unlock_file(f):","sourceCodeStart":3513,"sourceCodeEnd":3549,"githubUrl":"https://github.com/ytdl-org/youtube-dl/blob/956b8c585591b401a543e409accb163eeaaa1193/youtube_dl/utils.py#L3513-L3549","documentation":"Error \"Unlocking file failed: %r\" thrown in ytdl-org/youtube-dl.","triggerScenarios":"Thrown at youtube_dl/utils.py:3531 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check filesystem state and permissions; the lock could not be released."],"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"}