diff options
| author | Mattias Andrée <maandree@operamail.com> | 2014-02-27 14:00:13 +0100 | 
|---|---|---|
| committer | Mattias Andrée <maandree@operamail.com> | 2014-02-27 14:00:13 +0100 | 
| commit | 777c161c22c5b569642c128a42f739c6fb192d86 (patch) | |
| tree | e548e9f43a86a012df200ab7d2a4b95e69a4d370 | |
| parent | add empty module: util (diff) | |
| download | xpybar-777c161c22c5b569642c128a42f739c6fb192d86.tar.gz xpybar-777c161c22c5b569642c128a42f739c6fb192d86.tar.bz2 xpybar-777c161c22c5b569642c128a42f739c6fb192d86.tar.xz | |
add async and spawn
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
| -rw-r--r-- | src/util.py | 28 | 
1 files changed, 27 insertions, 1 deletions
| diff --git a/src/util.py b/src/util.py index 0c44cdb..936538d 100644 --- a/src/util.py +++ b/src/util.py @@ -16,6 +16,32 @@ GNU General Public License for more details.  You should have received a copy of the GNU General Public License  along with this program.  If not, see <http://www.gnu.org/licenses/>.  ''' +import sys +import threading +import subprocess -# TODO add utility functions + +def async(target, name = None, group = None): +    ''' +    Start a function asynchronously +     +    @param   target:()→void  The function +    @param   name:str?       The name of the thread +    @return  :Thread         A running deamon-thread running `target`, with the name `name` +    ''' +    t = threading.Thread(target = target, name = name) +    t.setDaemon(True) +    t.start() +    return t + + +def spawn(*command): +    ''' +    Spawn an external process +     +    @param   command:*str  The command line +    @return  :istream      The process's stdout +    ''' +    proc = process.Popen(list(command), stderr = sys.stderr, stdout = PIPE) +    return proc.stdout | 
