diff options
author | VG <vg@devys.org> | 2016-04-21 17:51:25 +0200 |
---|---|---|
committer | VG <vg@devys.org> | 2016-04-21 17:51:25 +0200 |
commit | 0da983c1f74c764e5cb98ddccdc15aaceb383814 (patch) | |
tree | 75f08a3599dd8b034e4b2c262976709fcc1f796e /test.py | |
parent | 4f46cb62cecd1ec3390536c21314a3c3ca1d27cb (diff) | |
download | teaqueue-0da983c1f74c764e5cb98ddccdc15aaceb383814.tar.gz teaqueue-0da983c1f74c764e5cb98ddccdc15aaceb383814.tar.bz2 teaqueue-0da983c1f74c764e5cb98ddccdc15aaceb383814.zip |
Auto-commit on 6d1dbe8495b5fafbc5f50d80268d0ca5b7b097be
Diffstat (limited to 'test.py')
-rw-r--r-- | test.py | 36 |
1 files changed, 36 insertions, 0 deletions
@@ -0,0 +1,36 @@ +#!/usr/bin/env python3 + + +import contextlib +import os +import random +import socket +import subprocess + + +procs = [] +procmax = 2 +s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) +with contextlib.suppress(FileNotFoundError): + os.unlink('socket') +s.bind(b'socket') +s.listen(0) +while True: + client, _ = s.accept() + line = client.recv(1024) + if not line.endswith(b'\n'): + client.close() + continue + filename = line.rstrip() + client.close() + + print('running for filename {}'.format(filename)) + + p = subprocess.Popen("sleep {} && echo ffmpeg {}" + .format(random.randint(1, 10), filename), shell=True) + + procs.append(p) + + if len(procs) >= procmax: + os.wait() + procs = list(p for p in procs if p.poll() is not None) |