aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/utils.py
diff options
context:
space:
mode:
authorYen Chi Hsuan <yan12125@gmail.com>2016-02-21 03:28:25 +0800
committerYen Chi Hsuan <yan12125@gmail.com>2016-02-21 03:32:03 +0800
commit399a76e67bca0beb4849ea90c4f40803fbd06ed3 (patch)
tree026614ca7178242e8e91a1ddaff340169d580d48 /youtube_dl/utils.py
parent7360db05b43741c2dfa1fd024e9c2f013ed97c9e (diff)
downloadyoutube-dl-399a76e67bca0beb4849ea90c4f40803fbd06ed3.tar.xz
[utils] Jython support: tolerate missing fcntl module
Diffstat (limited to 'youtube_dl/utils.py')
-rw-r--r--youtube_dl/utils.py20
1 files changed, 15 insertions, 5 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py
index a2c6780ca..17747be26 100644
--- a/youtube_dl/utils.py
+++ b/youtube_dl/utils.py
@@ -1217,13 +1217,23 @@ if sys.platform == 'win32':
raise OSError('Unlocking file failed: %r' % ctypes.FormatError())
else:
- import fcntl
+ # Some platforms, such as Jython, is missing fcntl
+ try:
+ import fcntl
- def _lock_file(f, exclusive):
- fcntl.flock(f, fcntl.LOCK_EX if exclusive else fcntl.LOCK_SH)
+ def _lock_file(f, exclusive):
+ fcntl.flock(f, fcntl.LOCK_EX if exclusive else fcntl.LOCK_SH)
- def _unlock_file(f):
- fcntl.flock(f, fcntl.LOCK_UN)
+ def _unlock_file(f):
+ fcntl.flock(f, fcntl.LOCK_UN)
+ except ImportError:
+ UNSUPPORTED_MSG = 'file locking is not supported on this platform'
+
+ def _lock_file(f, exclusive):
+ raise IOError(UNSUPPORTED_MSG)
+
+ def _unlock_file(f):
+ raise IOError(UNSUPPORTED_MSG)
class locked_file(object):