File: lock.py

package info (click to toggle)
python-apt 0.7.100.1%2Bsqueeze1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,748 kB
  • ctags: 1,919
  • sloc: cpp: 8,937; python: 5,750; makefile: 89; sh: 9
file content (47 lines) | stat: -rw-r--r-- 937 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python2.4
#
# Test for the pkgCache code
#

import apt_pkg
import sys
import os


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

    apt_pkg.init()

    # system-lock
    apt_pkg.PkgSystemLock()

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

    apt_pkg.PkgSystemUnLock()

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

    # try to get lock without error flag
    pid = os.fork()
    if pid == 0:
        # child
        fd = apt_pkg.GetLock(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.GetLock(lock, True)
        print "Lockfile fd (child): %s" % fd
        sys.exit(0)