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 859B

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