sound support
[saartuer.git] / libtuer.py
index 60f491be2d8226035b382e78ff97c2784ca3066c..e31ce2728497f1c2dab8bfadad7d3b7a153ec41c 100644 (file)
@@ -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