1
# -*- test-case-name: epsilon.test.test_process -*-
2
# Copyright (c) 2008 Divmod. See LICENSE for details.
5
Process and stdio related functionality.
10
from zope.interface import implements
12
from twisted.internet import reactor
13
from twisted.application.service import IService, Service
14
from twisted.internet.stdio import StandardIO
16
from epsilon.structlike import record
19
def spawnProcess(processProtocol, executable, args=(), env={},
20
path=None, uid=None, gid=None, usePTY=0,
22
"""Launch a process with a particular Python environment.
24
All arguments as to reactor.spawnProcess(), except for the
25
addition of an optional packages iterable. This should be
26
of strings naming packages the subprocess is to be able to
34
p = os.path.split(imp.find_module(pkg)[1])[0]
35
if p.startswith(os.path.join(sys.prefix, 'lib')):
38
pythonpath = list(set(pythonpath))
39
pythonpath.extend(env.get('PYTHONPATH', '').split(os.pathsep))
40
env['PYTHONPATH'] = os.pathsep.join(pythonpath)
42
return reactor.spawnProcess(processProtocol, executable, args,
43
env, path, uid, gid, usePTY)
45
def spawnPythonProcess(processProtocol, args=(), env={},
46
path=None, uid=None, gid=None, usePTY=0,
48
"""Launch a Python process
50
All arguments as to spawnProcess(), except the executable
53
return spawnProcess(processProtocol, sys.executable,
54
args, env, path, uid, gid, usePTY,
59
class StandardIOService(record('protocol'), Service):
61
Service for connecting a protocol to stdio.
63
def startService(self):
65
Connect C{self.protocol} to standard io.
67
StandardIO(self.protocol)