Skip to content

Commit fa3dbbf

Browse files
committed
Ignore locking errors if locks are not available
If $HOME is on a NFS, locking will fail with ENOLCK. Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
1 parent ba48179 commit fa3dbbf

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

bpython/filelock.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
try:
2727
import fcntl
28+
import errno
2829
has_fcntl = True
2930
except ImportError:
3031
has_fcntl = False
@@ -42,14 +43,20 @@ def __init__(self, fd, mode=None):
4243

4344
self.fd = fd
4445
self.mode = mode
46+
self.locked = False
4547

4648
def __enter__(self):
4749
if has_fcntl:
48-
fcntl.flock(self.fd, self.mode)
50+
try:
51+
fcntl.flock(self.fd, self.mode)
52+
self.locked = True
53+
except IOError as e:
54+
if e.errno != errno.ENOLCK:
55+
raise e
4956
return self
5057

5158
def __exit__(self, *args):
52-
if has_fcntl:
59+
if has_fcntl and self.locked:
5360
fcntl.flock(self.fd, fcntl.LOCK_UN)
5461

5562
# vim: sw=4 ts=4 sts=4 ai et

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy