#!/usr/bin/env python # Lock with mlock, unlock when face is detected import subprocess import threading locker = subprocess.Popen([ "mlock" ]) print("locker "+str(locker.pid)+" spawned") matcher = subprocess.Popen([ "./facewaiter.py" ]) 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" ])