From 497909693c6bcf5a6aef5c0dcb21d18ab6da6e60 Mon Sep 17 00:00:00 2001 From: Damien De Paoli Date: Mon, 8 Aug 2022 21:18:01 +1000 Subject: [PATCH] try/except for os.remove & remove DEBUG. Also deal with odd situation where we find a face then add it as a refimg and library cant find a face all of a sudden --- person.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/person.py b/person.py index 993322e..deb2e43 100644 --- a/person.py +++ b/person.py @@ -105,8 +105,15 @@ def AddRefimgToPerson( filename, person ): settings = Settings.query.first() model=AIModel.query.get(settings.default_refimg_model) refimg.face, face_locn = GenFace( filename, model=model.name ) - os.remove(filename) + try: + os.remove(filename) + except Exception as e: + # can fail "silently" here, if the face_locn worked, great, its only + # a tmp file in /tmp - if not, the next if will send a msg to the front-end + print( f"Failed to delete tmp file for refimg addition: {e}" ) + if not face_locn: + st.SetMessage( f"Failed to find face in Refimg:" ) raise Exception("Could not find face in uploaded reference image" ) return refimg.face_locn = json.dumps(face_locn) @@ -383,7 +390,6 @@ def remove_force_match_override(): FaceForceMatchOverride.query.filter( FaceForceMatchOverride.face_id==face_id ).delete() db.session.commit() - print( f"person_tag={person_tag}" ) # needed to use person_id in job below (allows consistent processing in job_mgr) p=Person.query.filter(Person.tag==person_tag).one()