Martin Dørum 4 vuotta sitten
vanhempi
commit
c27067167a
1 muutettua tiedostoa jossa 21 lisäystä ja 13 poistoa
  1. 21
    13
      lock.py

+ 21
- 13
lock.py Näytä tiedosto

@@ -4,26 +4,33 @@ import subprocess
import threading
import getpass
import os
import sys
import signal
import time
import glob

class I3Locker:
def __init__(self):
def __init__(self, lockpid):
self.killed = False
self.proc = None
self.lockpid = lockpid

def run(self):
self.proc = subprocess.Popen([ "mlock" ])
code = self.proc.wait()
if code == 0 or self.killed:
return 0
died = False
while not died and not self.killed:
try:
os.kill(self.lockpid, 0)
time.sleep(0.5)
except:
died = True

if self.killed:
return 1
else:
print("mlock exited with code "+str(code))
return -1
return 0

def kill(self):
self.killed = True
self.proc.terminate()
os.kill(self.lockpid, signal.SIGTERM)

class FaceLocker:
def __init__(self):
@@ -68,7 +75,9 @@ class FaceLocker:
# Match faces, blocks until a match is found or we're killed
self.runFaces(faceencs, paths, np, face_recognition, cv2)

if self.matching or self.killed:
if self.killed:
return 1
elif self.matching:
return 0
else:
return -1
@@ -110,7 +119,6 @@ class FaceLocker:
dist = dists[0]
distidx = 0
for i, d in enumerate(dists):
print(i, d)
if d < dist:
dist = d
distidx = i
@@ -144,7 +152,7 @@ class FaceLocker:
self.waitingProc.terminate()

lockers = [
I3Locker(),
I3Locker(int(sys.argv[1])),
FaceLocker(),
]

@@ -157,7 +165,7 @@ def runLocker(locker):
if l == locker:
continue
l.kill()
else:
elif ret != 1:
print(locker.__class__.__name__+" failed.")



Loading…
Peruuta
Tallenna