Browse Source

better locking

master
Martin Dørum 5 years ago
parent
commit
c988ef2344
2 changed files with 35 additions and 1 deletions
  1. 34
    0
      facelock.py
  2. 1
    1
      facematcher.py

+ 34
- 0
facelock.py View File

@@ -0,0 +1,34 @@
#!/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" ])

+ 1
- 1
facematcher.py View File

@@ -28,7 +28,7 @@ def match(paths, cap, show):
if cv2.mean(frame)[0] < 30:
continue

scale = 0.25
scale = 0.5
rgb_frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2RGB)
small_rgb_frame = cv2.resize(rgb_frame, (0, 0), fx=scale, fy=scale)


Loading…
Cancel
Save