Browse Source

hey

master
Martin Dørum 4 years ago
parent
commit
c27067167a
1 changed files with 21 additions and 13 deletions
  1. 21
    13
      lock.py

+ 21
- 13
lock.py View File

import threading import threading
import getpass import getpass
import os import os
import sys
import signal
import time import time
import glob import glob


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


def run(self): 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: else:
print("mlock exited with code "+str(code))
return -1
return 0


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


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


if self.matching or self.killed:
if self.killed:
return 1
elif self.matching:
return 0 return 0
else: else:
return -1 return -1
dist = dists[0] dist = dists[0]
distidx = 0 distidx = 0
for i, d in enumerate(dists): for i, d in enumerate(dists):
print(i, d)
if d < dist: if d < dist:
dist = d dist = d
distidx = i distidx = i
self.waitingProc.terminate() self.waitingProc.terminate()


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


if l == locker: if l == locker:
continue continue
l.kill() l.kill()
else:
elif ret != 1:
print(locker.__class__.__name__+" failed.") print(locker.__class__.__name__+" failed.")





Loading…
Cancel
Save