Skip to content

Commit 721b330

Browse files
committed
Fixed #42. Added support for file open **kwargs
1 parent 7689e1a commit 721b330

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

portalocker/utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class Lock(object):
6868
def __init__(
6969
self, filename, mode='a', timeout=DEFAULT_TIMEOUT,
7070
check_interval=DEFAULT_CHECK_INTERVAL, fail_when_locked=False,
71-
flags=LOCK_METHOD):
71+
flags=LOCK_METHOD, **file_open_kwargs):
7272
'''Lock manager with build-in timeout
7373
7474
filename -- filename
@@ -79,6 +79,7 @@ def __init__(
7979
check_interval -- check interval while waiting
8080
fail_when_locked -- after the initial lock failed, return an error
8181
or lock the file
82+
**file_open_kwargs -- The kwargs for the `open(...)` call
8283
8384
fail_when_locked is useful when multiple threads/processes can race
8485
when creating a file. If set to true than the system will wait till
@@ -102,6 +103,7 @@ def __init__(
102103
self.check_interval = check_interval
103104
self.fail_when_locked = fail_when_locked
104105
self.flags = flags
106+
self.file_open_kwargs = file_open_kwargs
105107

106108
def acquire(
107109
self, timeout=None, check_interval=None, fail_when_locked=None):
@@ -168,7 +170,7 @@ def release(self):
168170

169171
def _get_fh(self):
170172
'''Get a new filehandle'''
171-
return open(self.filename, self.mode)
173+
return open(self.filename, self.mode, **self.file_open_kwargs)
172174

173175
def _get_lock(self, fh):
174176
'''

0 commit comments

Comments
 (0)