build subprocess stdin near heartbeats

This commit is contained in:
Alan Hamlett 2018-09-13 19:39:05 -07:00
parent 48123d7409
commit f61a34eda7

View File

@ -542,19 +542,16 @@ class SendHeartbeatsThread(threading.Thread):
if self.has_extra_heartbeats: if self.has_extra_heartbeats:
cmd.append('--extra-heartbeats') cmd.append('--extra-heartbeats')
stdin = PIPE stdin = PIPE
extra_heartbeats = [self.build_heartbeat(**x) for x in self.extra_heartbeats] extra_heartbeats = json.dumps([self.build_heartbeat(**x) for x in self.extra_heartbeats])
extra_heartbeats = json.dumps(extra_heartbeats) inp = "{0}\n".format(extra_heartbeats).encode('utf-8')
else: else:
extra_heartbeats = None extra_heartbeats = None
stdin = None stdin = None
inp = None
log(DEBUG, ' '.join(obfuscate_apikey(cmd))) log(DEBUG, ' '.join(obfuscate_apikey(cmd)))
try: try:
process = Popen(cmd, stdin=stdin, stdout=PIPE, stderr=STDOUT) process = Popen(cmd, stdin=stdin, stdout=PIPE, stderr=STDOUT)
inp = None
if self.has_extra_heartbeats:
inp = "{0}\n".format(extra_heartbeats)
inp = inp.encode('utf-8')
output, err = process.communicate(input=inp) output, err = process.communicate(input=inp)
output = u(output) output = u(output)
retcode = process.poll() retcode = process.poll()