Take the lock on ``fh`` without waiting; False if another process holds it. Raises OSError when the file system cannot lock at all (e.g. some network mounts).
(fh)
| 69 | |
| 70 | |
| 71 | def _try_skill_lock(fh) -> bool: |
| 72 | """Take the lock on ``fh`` without waiting; False if another process holds it. |
| 73 | |
| 74 | Raises OSError when the file system cannot lock at all (e.g. some network |
| 75 | mounts). |
| 76 | """ |
| 77 | try: |
| 78 | if fcntl is not None: |
| 79 | fcntl.flock(fh.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB) |
| 80 | else: |
| 81 | fh.seek(0) |
| 82 | msvcrt.locking(fh.fileno(), msvcrt.LK_NBLCK, 1) |
| 83 | except OSError as exc: |
| 84 | if exc.errno in (errno.EAGAIN, errno.EWOULDBLOCK, errno.EACCES): |
| 85 | return False |
| 86 | raise |
| 87 | return True |
| 88 | |
| 89 | |
| 90 | def _release_skill_lock(fh) -> None: |