X-Git-Url: https://git.ralfj.de/saartuer.git/blobdiff_plain/8b136f42bf0c83f8aee52c315f7dbebc371cce1b..5a866fd8add83733d9e1cde55ecbd23f69661658:/libtuer.py?ds=sidebyside diff --git a/libtuer.py b/libtuer.py index 60f491b..e31ce27 100644 --- a/libtuer.py +++ b/libtuer.py @@ -1,4 +1,4 @@ -import logging, logging.handlers, os, time, queue, threading +import logging, logging.handlers, os, time, queue, threading, subprocess, multiprocessing # logging function class Logger: @@ -28,6 +28,17 @@ class Logger: logger = Logger() +# run a command asynchronously and log the return value if not 0 +# prefix must be a string identifying the code position where the call came from +def fire_and_forget (cmd, log, prefix): + def _fire_and_forget (cmd, log, prefix): + with open("/dev/null", "w") as fnull: + retcode = subprocess.call(cmd, stdout=fnull, stderr=fnull) + if retcode is not 0: + log("%sReturn code %d at command: %s" % (prefix,retcode,str(cmd))) + p = multiprocessing.Process(target=_fire_and_forget, args=(cmd,log,prefix)) + p.start() + # Threaded callback class class ThreadFunction(): _CALL = 0