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

Function _subclass_fork_script

tests/test_read_write_fork.py:907–942  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

905
906
907def _subclass_fork_script() -> str:
908 return textwrap.dedent(
909 """
910 from __future__ import annotations
911
912 import os
913 import sys
914
915 from filelock import ReadWriteLock
916
917 class DerivedReadWriteLock(ReadWriteLock):
918 pass
919
920 lock_path = sys.argv[1]
921 inherited_lock = DerivedReadWriteLock(lock_path)
922 child_pid = os.fork()
923 if child_pid == 0:
924 if sys.implementation.name == "pypy":
925 try:
926 DerivedReadWriteLock(lock_path)
927 except RuntimeError as error:
928 assert str(error) == (
929 "ReadWriteLock is unavailable in a PyPy fork child; exec or exit before using it"
930 )
931 else:
932 raise AssertionError("PyPy child constructed a lock after fork")
933 else:
934 child_lock = DerivedReadWriteLock(lock_path)
935 assert child_lock is not inherited_lock
936 with child_lock.read_lock():
937 pass
938 sys.exit(0)
939 _, status = os.waitpid(child_pid, 0)
940 assert os.waitstatus_to_exitcode(status) == 0
941 """
942 )
943
944
945def _async_fork_script() -> str:

Calls

no outgoing calls

Tested by

no test coverage detected