]> git.mxchange.org Git - fba.git/blobdiff - fba/helpers/locking.py
Continued:
[fba.git] / fba / helpers / locking.py
index 27f5eac10232046e8b8e168521423ede06f5ea52..f553d0435a6f9068a10c7786a4e22dccb58cb5ea 100644 (file)
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
+import logging
 import os
 import sys
 import tempfile
 import zc.lockfile
 
+logging.basicConfig(level=logging.INFO)
+logger = logging.getLogger(__name__)
+
 # Lock file
 lockfile = tempfile.gettempdir() + '/fba.lock'
 LOCK = None
 
 def acquire():
     global LOCK
-    # DEBUG: print("DEBUG: CALLED!")
+    logger.debug("CALLED!")
 
     try:
-        # DEBUG: print(f"DEBUG: Acquiring lock: '{lockfile}'")
+        logger.debug("Acquiring lock: lockfile='%s'", lockfile)
         LOCK = zc.lockfile.LockFile(lockfile)
-        # DEBUG: print("DEBUG: Lock obtained.")
+        logger.debug("Lock obtained.")
 
     except zc.lockfile.LockError:
-        print(f"ERROR: Cannot aquire lock: '{lockfile}'")
+        logger.error("Cannot aquire lock: lockfile='%s'", lockfile)
         sys.exit(100)
 
-    # DEBUG: print("DEBUG: EXIT!")
+    logger.debug("EXIT!")
 
 def release():
-    # DEBUG: print("DEBUG: CALLED!")
+    logger.debug("CALLED!")
     if LOCK is not None:
-        # DEBUG: print("DEBUG: Releasing lock ...")
+        logger.debug("Releasing lock ...")
         LOCK.close()
-        # DEBUG: print(f"DEBUG: Deleting lockfile='{lockfile}' ...")
+
+        logger.debug("Deleting lockfile='%s' ...", lockfile)
         os.remove(lockfile)
 
-    # DEBUG: print("DEBUG: EXIT!")
+    logger.debug("EXIT!")