MCPcopy Create free account
hub / github.com/tox-dev/filelock / _recursive_acquisition_script

Function _recursive_acquisition_script

tests/test_read_write_fork.py:440–481  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

438
439
440def _recursive_acquisition_script() -> str:
441 return textwrap.dedent(
442 """
443 from __future__ import annotations
444
445 import sys
446
447 from filelock import ReadWriteLock
448
449 lock_path, operation = sys.argv[1:]
450 lock = ReadWriteLock(lock_path)
451 armed = True
452
453 from typing import TYPE_CHECKING
454
455 if TYPE_CHECKING:
456 from _typeshed import Unused
457
458 def audit_hook(event: str, _args: Unused) -> None:
459 if armed and event == "sqlite3.connect":
460 if operation == "acquire":
461 lock.acquire_read()
462 elif operation == "release":
463 lock.release()
464 else:
465 lock.close()
466
467 sys.addaudithook(audit_hook)
468 try:
469 lock.acquire_read()
470 except RuntimeError as error:
471 assert str(error) == (
472 f"Cannot {operation} ReadWriteLock on {lock_path} while acquisition is active in this thread"
473 )
474 else:
475 raise AssertionError(f"recursive {operation} succeeded")
476
477 armed = False
478 with lock.read_lock():
479 pass
480 """
481 )
482
483
484def _ctypes_signature_script() -> str: # pragma: <3.12 cover

Calls

no outgoing calls

Tested by

no test coverage detected