equal
deleted
inserted
replaced
19 |
19 |
20 from . import ( |
20 from . import ( |
21 encoding, |
21 encoding, |
22 error, |
22 error, |
23 pycompat, |
23 pycompat, |
|
24 util, |
24 ) |
25 ) |
25 |
26 |
26 from .utils import ( |
27 from .utils import ( |
27 procutil, |
28 procutil, |
28 ) |
29 ) |
175 |
176 |
176 _host = None |
177 _host = None |
177 |
178 |
178 def __init__(self, vfs, fname, timeout=-1, releasefn=None, acquirefn=None, |
179 def __init__(self, vfs, fname, timeout=-1, releasefn=None, acquirefn=None, |
179 desc=None, inheritchecker=None, parentlock=None, |
180 desc=None, inheritchecker=None, parentlock=None, |
180 dolock=True): |
181 signalsafe=True, dolock=True): |
181 self.vfs = vfs |
182 self.vfs = vfs |
182 self.f = fname |
183 self.f = fname |
183 self.held = 0 |
184 self.held = 0 |
184 self.timeout = timeout |
185 self.timeout = timeout |
185 self.releasefn = releasefn |
186 self.releasefn = releasefn |
187 self.desc = desc |
188 self.desc = desc |
188 self._inheritchecker = inheritchecker |
189 self._inheritchecker = inheritchecker |
189 self.parentlock = parentlock |
190 self.parentlock = parentlock |
190 self._parentheld = False |
191 self._parentheld = False |
191 self._inherited = False |
192 self._inherited = False |
|
193 if signalsafe: |
|
194 self._maybedelayedinterrupt = _delayedinterrupt |
|
195 else: |
|
196 self._maybedelayedinterrupt = util.nullcontextmanager |
192 self.postrelease = [] |
197 self.postrelease = [] |
193 self.pid = self._getpid() |
198 self.pid = self._getpid() |
194 if dolock: |
199 if dolock: |
195 self.delay = self.lock() |
200 self.delay = self.lock() |
196 if self.acquirefn: |
201 if self.acquirefn: |
242 lockname = '%s:%d' % (lock._host, self.pid) |
247 lockname = '%s:%d' % (lock._host, self.pid) |
243 retry = 5 |
248 retry = 5 |
244 while not self.held and retry: |
249 while not self.held and retry: |
245 retry -= 1 |
250 retry -= 1 |
246 try: |
251 try: |
247 with _delayedinterrupt(): |
252 with self._maybedelayedinterrupt(): |
248 self.vfs.makelock(lockname, self.f) |
253 self.vfs.makelock(lockname, self.f) |
249 self.held = 1 |
254 self.held = 1 |
250 except (OSError, IOError) as why: |
255 except (OSError, IOError) as why: |
251 if why.errno == errno.EEXIST: |
256 if why.errno == errno.EEXIST: |
252 locker = self._readlock() |
257 locker = self._readlock() |