Changeset b1261cb in mod_gnutls
- Timestamp:
- Dec 12, 2019, 4:58:01 PM (13 months ago)
- Branches:
- asyncio, master, proxy-ticket
- Children:
- f3a3f6f
- Parents:
- 4459cdd
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
test/mgstest/__init__.py
r4459cdd rb1261cb 17 17 """Python modules for the mod_gnutls test suite.""" 18 18 19 import sys 20 21 import fcntl 22 from contextlib import contextmanager 23 19 24 class TestExpectationFailed(Exception): 20 25 """Raise if a test failed. The constructor should be called with a 21 26 string describing the problem.""" 22 27 pass 28 29 30 31 @contextmanager 32 def lockfile(file, nolock=False): 33 """Context manager for an optional file-based mutex. 34 35 Unless nolock=True the process must hold a lock on the given file 36 before entering the context. The lock is released when leaving the 37 context. 38 39 """ 40 if nolock: 41 yield 42 else: 43 with open(file, 'w') as lockfile: 44 try: 45 print(f'Aquiring lock on {file}...', file=sys.stderr) 46 fcntl.flock(lockfile, fcntl.LOCK_EX) 47 print(f'Got lock on {file}.', file=sys.stderr) 48 yield 49 finally: 50 print(f'Unlocking {file}...', file=sys.stderr) 51 fcntl.flock(lockfile, fcntl.LOCK_UN) 52 print(f'Unlocked {file}.', file=sys.stderr)
Note: See TracChangeset
for help on using the changeset viewer.