You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

facelock.py 848B

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/env python
  2. import subprocess
  3. import threading
  4. locker = subprocess.Popen([ "mlock" ])
  5. print("locker "+str(locker.pid)+" spawned")
  6. matcher = subprocess.Popen([ "sh", "-c", "./facematcher.py match -d 2 faces/$USER/*" ])
  7. print("matcher "+str(matcher.pid)+" spawned")
  8. def waitfor(x, others):
  9. code = x.wait()
  10. if code != 0:
  11. print(str(x.pid)+" died with code "+str(code)+"!")
  12. else:
  13. print(str(x.pid)+" died.")
  14. for other in others:
  15. if other.poll() == None:
  16. print("killing "+str(other.pid))
  17. other.terminate()
  18. threads = [
  19. threading.Thread(target=waitfor, args=(locker, [ matcher ])),
  20. threading.Thread(target=waitfor, args=(matcher, [ locker ])),
  21. ]
  22. for th in threads:
  23. th.start()
  24. for th in threads:
  25. th.join()
  26. subprocess.call([ "pkill", "i3lock" ])