1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
#!/usr/bin/python
import os
from time import sleep
import subprocess
import atexit
class Process(object):
processes = []
@classmethod
def new(clazz, *args, **kw):
clazz.processes.append(subprocess.Popen(*args, **kw))
return clazz.processes[-1]
@classmethod
def atexit(clazz):
for p in reversed(clazz.processes):
print "child %s" % p.pid
if False:
slp = subprocess.Popen(['/usr/bin/sleep', '10000'])
print "wait on %d" % slp.pid
slp.wait()
if len(clazz.processes) == 0:
return
for p in reversed(clazz.processes):
print "kill %s" % p.pid
try:
p.kill()
except:
pass
if not any(p.poll() for p in clazz.processes):
return
sleep(1)
for p in reversed(clazz.processes):
if not p.poll():
print "terminate %s" % p.pid
try:
p.terminate()
except:
pass
atexit.register(Process.atexit)
def which(prog):
for path_element in os.environ['PATH'].split(':'):
candidate = os.path.join(path_element, prog)
if os.path.exists(candidate):
return candidate
return None
client_executable = which('remote-viewer')
if not client_executable:
raise SystemExit('missing remote-viewer in path')
def launch_xspice(port):
basedir = '/tmp/xspice_test_audio'
if not os.path.exists(basedir):
os.mkdir(basedir)
assert(os.path.exists(basedir))
xspice = Process.new(['../scripts/Xspice', '--port', str(port), '--auto', '--audio-fifo-dir', basedir, '--disable-ticketing', ':15.0'])
xspice.audio_fifo_dir = basedir
return xspice
def launch_client(port):
client = Process.new([client_executable, 'spice://localhost:%s' % port])
return client
if __name__ == '__main__':
launch_xspice(port=8000)
|