HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //proc/1233/root/home/arjun/python-apt/tests/old/lock.py
#!/usr/bin/env python2.4
#
# Test for the pkgCache code
#

import os
import sys

import apt_pkg

if __name__ == "__main__":
    lock = "/tmp/test.lck"

    apt_pkg.init()

    # system-lock
    apt_pkg.pkgsystem_lock()

    pid = os.fork()
    if pid == 0:
        try:
            apt_pkg.pkgsystem_lock()
        except SystemError as s:
            print("Can't get lock: (error text:\n%s)" % s)
        sys.exit(0)

    apt_pkg.pkgsystem_unlock()

    # low-level lock
    fd = apt_pkg.get_lock(lock, True)
    print("Lockfile fd: %s" % fd)

    # try to get lock without error flag
    pid = os.fork()
    if pid == 0:
        # child
        fd = apt_pkg.get_lock(lock, False)
        print("Lockfile fd (child): %s" % fd)
        sys.exit(0)

    # try to get lock with error flag
    pid = os.fork()
    if pid == 0:
        # child
        fd = apt_pkg.get_lock(lock, True)
        print("Lockfile fd (child): %s" % fd)
        sys.exit(0)