|
12345678910111213141516171819202122232425262728293031323334 |
- #!/usr/bin/env python
-
- import subprocess
- import threading
-
- locker = subprocess.Popen([ "mlock" ])
-
- print("locker "+str(locker.pid)+" spawned")
- matcher = subprocess.Popen([ "sh", "-c", "./facematcher.py match -d 2 faces/$USER/*" ])
- print("matcher "+str(matcher.pid)+" spawned")
-
- def waitfor(x, others):
- code = x.wait()
- if code != 0:
- print(str(x.pid)+" died with code "+str(code)+"!")
- else:
- print(str(x.pid)+" died.")
- for other in others:
- if other.poll() == None:
- print("killing "+str(other.pid))
- other.terminate()
-
- threads = [
- threading.Thread(target=waitfor, args=(locker, [ matcher ])),
- threading.Thread(target=waitfor, args=(matcher, [ locker ])),
- ]
-
- for th in threads:
- th.start()
-
- for th in threads:
- th.join()
-
- subprocess.call([ "pkill", "i3lock" ])
|