Skip to content
This repository has been archived by the owner on Apr 24, 2018. It is now read-only.

Allow passing custom parameters to subprocess open. #81

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions envoy/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def _is_alive(thread):


class Command(object):

def __init__(self, cmd):
self.cmd = cmd
self.process = None
Expand All @@ -56,23 +57,34 @@ def __init__(self, cmd):
self.data = None
self.exc = None

def run(self, data, timeout, kill_timeout, env, cwd):
def get_default_parameters(self):
"""Returns default subprocess parameters
"""
return {
"universal_newlines": True,
"shell": False,
"bufsize": 0
}

def run(self, data, timeout, kill_timeout, env, cwd, **kw):
self.data = data
environ = dict(os.environ)
environ.update(env or {})

def target():

parameters = self.get_default_parameters()
parameters.update(kw)

try:
self.process = subprocess.Popen(self.cmd,
universal_newlines=True,
shell=False,
self.process = subprocess.Popen(
self.cmd,
env=environ,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
bufsize=0,
cwd=cwd,
**parameters
)

if sys.version_info[0] >= 3:
Expand Down